-
Notifications
You must be signed in to change notification settings - Fork 12
/
multicasthandler.go
76 lines (68 loc) · 1.98 KB
/
multicasthandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"code.google.com/p/goprotobuf/proto"
"github.com/idealeak/goserver/core/logger"
"github.com/idealeak/goserver/core/netlib"
"github.com/idealeak/goserver/srvlib"
"github.com/idealeak/goserver/srvlib/protocol"
)
var (
MulticastMaker = &MulticastPacketFactory{}
)
type MulticastPacketFactory struct {
}
type MulticastHandler struct {
}
func init() {
netlib.RegisterHandler(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), &MulticastHandler{})
netlib.RegisterFactory(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), MulticastMaker)
}
func (this *MulticastPacketFactory) CreatePacket() interface{} {
pack := &protocol.SSPacketMulticast{}
return pack
}
func (this *MulticastPacketFactory) CreateMulticastPacket(packetid int, data interface{}, sis ...*protocol.MCSessionUnion) (proto.Message, error) {
pack := &protocol.SSPacketMulticast{
Sessions: sis,
PacketId: proto.Int(packetid),
}
if byteData, ok := data.([]byte); ok {
pack.Data = byteData
} else {
byteData, err := netlib.MarshalPacket(packetid, data)
if err == nil {
pack.Data = byteData
} else {
logger.Logger.Info("MulticastPacketFactory.CreateMulticastPacket err:", err)
return nil, err
}
}
proto.SetDefaults(pack)
return pack, nil
}
func (this *MulticastHandler) Process(s *netlib.Session, packetid int, data interface{}) error {
if mp, ok := data.(*protocol.SSPacketMulticast); ok {
pd := mp.GetData()
sis := mp.GetSessions()
for _, si := range sis {
cs := si.GetMccs()
if cs != nil {
sid := srvlib.SessionId(cs.GetSId())
bundleId := sid.SeqId()
bs := BundleMgrSington.GetBundleSession(uint16(bundleId))
if bs != nil {
bs.Send(int(mp.GetPacketId()), pd)
}
} else {
ss := si.GetMcss()
if ss != nil {
ns := srvlib.ServerSessionMgrSington.GetSession(int(ss.GetSArea()), int(ss.GetSType()), int(ss.GetSId()))
if ns != nil {
ns.Send(int(mp.GetPacketId()), pd /*, s.GetSessionConfig().IsInnerLink*/)
}
}
}
}
}
return nil
}