本文整理汇总了Golang中github.com/idealeak/goserver/core/netlib.Session.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.GetAttribute方法的具体用法?Golang Session.GetAttribute怎么用?Golang Session.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/idealeak/goserver/core/netlib.Session
的用法示例。
在下文中一共展示了Session.GetAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: OnRegiste
func (this *serviceMgr) OnRegiste(s *netlib.Session) {
if this == nil || s == nil {
return
}
if s.GetAttribute(SessionAttributeServiceFlag) == nil {
return
}
attr := s.GetAttribute(SessionAttributeServerInfo)
if attr != nil {
if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
services := GetCareServicesBySession(srvInfo.GetType())
for _, v1 := range services {
if v2, has := this.servicesPool[v1]; has {
for _, v3 := range v2 {
func(si *protocol.ServiceInfo, sInfo *protocol.SSSrvRegiste) {
pack := &protocol.SSServiceInfo{}
proto.SetDefaults(pack)
pack.Service = si
logger.Trace("serviceMgr.OnRegiste Server Type=", sInfo.GetType(), " Id=", sInfo.GetId(), " Name=", sInfo.GetName(), " careful => Service=", si)
s.Send(pack)
}(v3, srvInfo)
}
}
}
}
}
}
示例2: RegisteSession
func (ssm *ServerSessionMgr) RegisteSession(s *netlib.Session) bool {
attr := s.GetAttribute(SessionAttributeServerInfo)
if attr != nil {
if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
logger.Tracef("ServerSessionMgr.RegisteSession %v", srvInfo)
areaId := int(srvInfo.GetAreaId())
srvType := int(srvInfo.GetType())
srvId := int(srvInfo.GetId())
if a, exist := ssm.sessions[areaId]; !exist {
ssm.sessions[areaId] = make(map[int]map[int]*netlib.Session)
a = ssm.sessions[areaId]
a[srvType] = make(map[int]*netlib.Session)
} else {
if _, exist := a[srvType]; !exist {
a[srvType] = make(map[int]*netlib.Session)
}
}
ssm.sessions[areaId][srvType][srvId] = s
if ssm.listener != nil {
ssm.listener.OnRegiste(s)
}
}
} else {
logger.Tracef("ServerSessionMgr.RegisteSession SessionAttributeServerInfo=nil")
}
return true
}
示例3: 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
}
示例4: UnregisteSession
func (csm *ClientSessionMgr) UnregisteSession(s *netlib.Session) bool {
attr := s.GetAttribute(SessionAttributeClientSession)
if attr != nil {
if sid, ok := attr.(SessionId); ok {
delete(csm.sessions, sid.Get())
logger.Tracef("client session %v unregiste", sid.Get())
}
}
return true
}
示例5: RegisteSession
func (csm *ClientSessionMgr) RegisteSession(s *netlib.Session) bool {
attr := s.GetAttribute(SessionAttributeClientSession)
if attr == nil {
sid := NewSessionId(s)
s.SetAttribute(SessionAttributeClientSession, sid)
csm.sessions[sid.Get()] = s
logger.Tracef("client session %v registe", sid.Get())
}
return true
}
示例6: ClearServiceBySession
func (this *serviceMgr) ClearServiceBySession(s *netlib.Session) {
attr := s.GetAttribute(SessionAttributeServiceInfo)
if attr != nil {
if services, ok := attr.([]*protocol.ServiceInfo); ok {
for _, service := range services {
this.UnregisteService(service)
}
}
s.RemoveAttribute(SessionAttributeServiceInfo)
}
}
示例7: Process
func (this *PacketSlicesHandler) Process(s *netlib.Session, data interface{}) error {
if packetslices, ok := data.(*protocol.SSPacketSlices); ok {
seqNo := int(packetslices.GetSeqNo())
if seqNo < 1 {
return errors.New("PacketSlicesHandler unexpect packet seq:" + strconv.Itoa(seqNo))
}
totalSize := int(packetslices.GetTotalSize())
if totalSize > s.GetSessionConfig().MaxPacket {
return errors.New("PacketSlicesHandler exceed MaxPacket size:" + strconv.Itoa(s.GetSessionConfig().MaxPacket) + " size=" + strconv.Itoa(totalSize))
}
attr := s.GetAttribute(SessionAttributeBigBuf)
if seqNo == 1 {
if attr == nil {
attr = bytes.NewBuffer(make([]byte, 0, packetslices.GetTotalSize()))
s.SetAttribute(SessionAttributeBigBuf, attr)
}
}
if seqNo > 1 {
if attr == nil {
return errors.New("PacketSlicesHandler Incorrect packet seq, expect seq=1")
}
} else if attr == nil {
return errors.New("PacketSlicesHandler get bytesbuf failed")
}
buf := attr.(*bytes.Buffer)
if seqNo == 1 {
buf.Reset()
}
if buf.Len() != int(packetslices.GetOffset()) {
return errors.New("PacketSlicesHandler get next packet offset error")
}
buf.Write(packetslices.GetPacketData())
if buf.Len() == totalSize {
packetid, pck, err := netlib.UnmarshalPacket(buf.Bytes())
if err != nil {
return err
}
h := netlib.GetHandler(packetid)
if h != nil {
h.Process(s, pck)
}
}
}
return nil
}
示例8: UnregisteSession
func (ssm *ServerSessionMgr) UnregisteSession(s *netlib.Session) bool {
attr := s.GetAttribute(SessionAttributeServerInfo)
if attr != nil {
if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
logger.Tracef("ServerSessionMgr.UnregisteSession %v", srvInfo)
areaId := int(srvInfo.GetAreaId())
srvType := int(srvInfo.GetType())
srvId := int(srvInfo.GetId())
if a, exist := ssm.sessions[areaId]; exist {
if b, exist := a[srvType]; exist {
delete(b, srvId)
if ssm.listener != nil {
ssm.listener.OnUnregiste(s)
}
}
}
}
}
return true
}