本文整理匯總了Golang中github.com/idealeak/goserver/core/netlib.Session.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Close方法的具體用法?Golang Session.Close怎麽用?Golang Session.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/idealeak/goserver/core/netlib.Session
的用法示例。
在下文中一共展示了Session.Close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OnSessionOpened
func (ctf *ConnectionThrottleFilter) OnSessionOpened(s *netlib.Session) bool {
if !ctf.isConnectionOk(s) {
s.Close()
return false
}
return true
}
示例2: OnPacketReceived
func (af *AuthenticationFilter) OnPacketReceived(s *netlib.Session, packetid int, packet interface{}) bool {
if s.GetAttribute(SessionAttributeAuth) == nil {
if auth, ok := packet.(*protocol.SSPacketAuth); ok {
h := md5.New()
rawText := fmt.Sprintf("%v;%v", auth.GetTimestamp(), s.GetSessionConfig().AuthKey)
logger.Tracef("AuthenticationFilter rawtext=%v IsInnerLink(%v)", rawText, s.GetSessionConfig().IsInnerLink)
h.Write([]byte(rawText))
expectKey := hex.EncodeToString(h.Sum(nil))
if expectKey != auth.GetAuthKey() {
if af.SessionAuthHandler != nil {
af.SessionAuthHandler(s, false)
}
s.Close()
logger.Tracef("AuthenticationFilter AuthKey error[expect:%v get:%v]", expectKey, auth.GetAuthKey())
return false
}
s.SetAttribute(SessionAttributeAuth, true)
if af.SessionAuthHandler != nil {
af.SessionAuthHandler(s, true)
}
return false
} else {
s.Close()
logger.Warn("AuthenticationFilter packet not expect")
return false
}
}
return true
}
示例3: OnSessionOpened
func (sfcb *SessionHandlerClientBalance) OnSessionOpened(s *netlib.Session) {
logger.Trace("SessionHandlerClientBalance.OnSessionOpened")
services := srvlib.ServiceMgr.GetServices(srvlib.ClientServiceType)
if services != nil {
/*清理掉線的gate*/
for k, _ := range sfcb.gates {
if _, has := services[k]; !has {
delete(sfcb.gates, k)
}
}
/*補充新上線的gate*/
for k, v := range services {
if _, has := sfcb.gates[k]; !has {
sfcb.gates[k] = &gateService{ServiceInfo: v, active: true}
}
}
}
/*查找最小負載的gate*/
var mls *libproto.ServiceInfo
var min = 100000
for _, v := range sfcb.gates {
if v.active && v.load < min {
mls = v.ServiceInfo
}
}
pack := &protocol.SCGateInfo{}
if mls != nil {
pack.SrvType = proto.Int32(mls.GetSrvType())
pack.SrvId = proto.Int32(mls.GetSrvId())
pack.AuthKey = proto.String(mls.GetAuthKey())
pack.Ip = proto.String(mls.GetIp())
pack.Port = proto.Int32(mls.GetPort())
}
proto.SetDefaults(pack)
s.Send(pack)
time.AfterFunc(time.Second*5, func() { s.Close() })
}
示例4: blockSession
func (blf *BlackListFilter) blockSession(s *netlib.Session) {
s.Close()
}