-
Notifications
You must be signed in to change notification settings - Fork 11
/
clientsessionload.go
52 lines (42 loc) · 1.44 KB
/
clientsessionload.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
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/mmo/protocol"
"github.com/idealeak/goserver/srvlib"
)
var (
SessionHandlerClientLoadName = "handler-client-load"
)
type SessionHandlerClientLoad struct {
netlib.BasicSessionHandler
}
func (sfcl SessionHandlerClientLoad) GetName() string {
return SessionHandlerClientLoadName
}
func (sfcl *SessionHandlerClientLoad) GetInterestOps() uint {
return 1<<netlib.InterestOps_Opened | 1<<netlib.InterestOps_Closed
}
func (sfcl *SessionHandlerClientLoad) OnSessionOpened(s *netlib.Session) {
sfcl.reportLoad(s)
}
func (sfcl *SessionHandlerClientLoad) OnSessionClosed(s *netlib.Session) {
sfcl.reportLoad(s)
}
func (sfcl *SessionHandlerClientLoad) reportLoad(s *netlib.Session) {
sc := s.GetSessionConfig()
pack := &protocol.ServerLoad{
SrvType: proto.Int32(int32(sc.Type)),
SrvId: proto.Int32(int32(sc.Id)),
CurLoad: proto.Int32(int32(srvlib.ClientSessionMgrSington.Count())),
}
proto.SetDefaults(pack)
srvlib.ServerSessionMgrSington.Broadcast(int(protocol.MmoPacketID_PACKET_SC_GATEINFO), pack, netlib.Config.SrvInfo.AreaID, srvlib.BalanceServerType)
logger.Logger.Tracef("SessionHandlerClientLoad.reportLoad %v", pack)
}
func init() {
netlib.RegisteSessionHandlerCreator(SessionHandlerClientLoadName, func() netlib.SessionHandler {
return &SessionHandlerClientLoad{}
})
}