本文整理汇总了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()
}