当前位置: 首页>>代码示例>>Golang>>正文


Golang Session.SetAttribute方法代码示例

本文整理汇总了Golang中github.com/idealeak/goserver/core/netlib.Session.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.SetAttribute方法的具体用法?Golang Session.SetAttribute怎么用?Golang Session.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/idealeak/goserver/core/netlib.Session的用法示例。


在下文中一共展示了Session.SetAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:zwczou,项目名称:goserver,代码行数:29,代码来源:authentication.go

示例2: OnSessionOpened

func (this *SessionHandlerServiceRegiste) OnSessionOpened(s *netlib.Session) {
	sc := s.GetSessionConfig()
	if sc.IsClient {
		/*报告自己的监听信息*/
		srvlib.ServiceMgr.ReportService(s)
	} else {
		s.SetAttribute(srvlib.SessionAttributeServiceFlag, 1)
	}
}
开发者ID:zwczou,项目名称:goserver,代码行数:9,代码来源:serverserviceregiste.go

示例3: 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
}
开发者ID:zwczou,项目名称:goserver,代码行数:10,代码来源:clientsessionmgr.go

示例4: 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
}
开发者ID:zwczou,项目名称:goserver,代码行数:46,代码来源:packetslices.go

示例5: RegisteService

func (this *serviceMgr) RegisteService(s *netlib.Session, services []*protocol.ServiceInfo) {
	if this == nil || services == nil || len(services) == 0 {
		return
	}

	s.SetAttribute(SessionAttributeServiceInfo, services)
	for _, service := range services {
		srvid := service.GetSrvId()
		srvtype := service.GetSrvType()
		if _, has := this.servicesPool[srvtype]; !has {
			this.servicesPool[srvtype] = make(map[int32]*protocol.ServiceInfo)
		}
		this.servicesPool[srvtype][srvid] = service

		pack := &protocol.SSServiceInfo{}
		pack.Service = service
		proto.SetDefaults(pack)
		sessiontypes := GetCareSessionsByService(service.GetSrvType())
		areaId := service.GetAreaId()
		for _, v1 := range sessiontypes {
			ServerSessionMgrSington.Broadcast(pack, int(areaId), int(v1))
		}
	}
}
开发者ID:zwczou,项目名称:goserver,代码行数:24,代码来源:servicemgr.go


注:本文中的github.com/idealeak/goserver/core/netlib.Session.SetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。