/
clientsessionload.go
50 lines (40 loc) · 1.35 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
package main
import (
"github.com/breezedup/goserver/core/logger"
"github.com/breezedup/goserver/core/netlib"
"github.com/breezedup/goserver/mmo/protocol"
"github.com/breezedup/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: int32(sc.Type),
SrvId: int32(sc.Id),
CurLoad: int32(srvlib.ClientSessionMgrSington.Count()),
}
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{}
})
}