-
Notifications
You must be signed in to change notification settings - Fork 11
/
packetdispatchhandler.go
55 lines (49 loc) · 1.48 KB
/
packetdispatchhandler.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
package main
import (
"bytes"
"sync/atomic"
"code.google.com/p/goprotobuf/proto"
"games.jiexunjiayin.com/jxjyqp/protocol"
"github.com/idealeak/goserver/core/builtin/filter"
"github.com/idealeak/goserver/core/logger"
"github.com/idealeak/goserver/core/netlib"
)
func init() {
netlib.RegisteErrorPacketHandlerCreator("packetdispatchhandler", func() netlib.ErrorPacketHandler {
return netlib.ErrorPacketHandlerWrapper(func(s *netlib.Session, packetid int, logicNo uint32, data []byte) bool {
if s.GetAttribute(filter.SessionAttributeAuth) == nil {
logger.Logger.Trace("packetdispatchhandler session not auth! ")
return false
}
bs := BundleMgrSington.GetBundleSession(uint16(s.GroupId))
if bs == nil {
logger.Logger.Trace("packetdispatchhandler BundleSession is nil! ")
return false
}
if atomic.CompareAndSwapUint32(&bs.rcvLogicNo, logicNo-1, logicNo) {
var ss *netlib.Session
if packetid >= 2000 && packetid < 3000 {
ss = bs.worldsrvSession
} else {
ss = bs.gamesrvSession
}
if ss == nil {
logger.Logger.Trace("packetdispatchhandler redirect server session is nil ", packetid)
return true
}
//must copy
buf := bytes.NewBuffer(nil)
buf.Write(data)
pack := &protocol.SSTransmit{
SessionId: proto.Int64(s.Sid),
PacketData: buf.Bytes(),
}
proto.SetDefaults(pack)
ss.Send(int(protocol.MmoPacketID_PACKET_SS_PACKET_TRANSMIT), pack)
return true
}
//丢掉
return false
})
})
}