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


Golang netlib.Session类代码示例

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


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

示例1: OnSessionOpened

func (ctf *ConnectionThrottleFilter) OnSessionOpened(s *netlib.Session) bool {
	if !ctf.isConnectionOk(s) {
		s.Close()
		return false
	}
	return true
}
开发者ID:zwczou,项目名称:goserver,代码行数:7,代码来源:connectionthrottle.go

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

示例3: 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

示例4: OnSessionOpened

func (sfl *SessionHandlerSrvRegiste) OnSessionOpened(s *netlib.Session) {
	registePacket := &protocol.SSSrvRegiste{
		Id:     proto.Int(netlib.Config.SrvInfo.Id),
		Type:   proto.Int(netlib.Config.SrvInfo.Type),
		AreaId: proto.Int(netlib.Config.SrvInfo.AreaID),
		Name:   proto.String(netlib.Config.SrvInfo.Name),
	}
	proto.SetDefaults(registePacket)
	s.Send(registePacket)
}
开发者ID:zwczou,项目名称:goserver,代码行数:10,代码来源:serversessionregiste.go

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

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

示例7: Process

func (this *SCPacketPongHandler) Process(session *netlib.Session, data interface{}) error {
	if pong, ok := data.(*protocol.SCPacketPong); ok {
		ping := &protocol.CSPacketPing{
			TimeStamb: proto.Int64(time.Now().Unix()),
			Message:   pong.GetMessage(),
		}
		proto.SetDefaults(ping)
		session.Send(ping)
	}
	return nil
}
开发者ID:zwczou,项目名称:goserver,代码行数:11,代码来源:scpacketponghandler.go

示例8: reportLoad

func (sfcl *SessionHandlerClientLoad) reportLoad(s *netlib.Session) {
	sc := s.GetSessionConfig()
	pack := &protocol.ServerLoad{
		SrvType: proto.Int32(int32(sc.Type)),
		SrvId:   proto.Int32(int32(sc.Id)),
		CurLoad: proto.Int32(int32(srvlib.ClientSessionMgrSington.Count())),
	}
	proto.SetDefaults(pack)
	srvlib.ServerSessionMgrSington.Broadcast(pack, netlib.Config.SrvInfo.AreaID, srvlib.BalanceServerType)
	logger.Tracef("SessionHandlerClientLoad.reportLoad %v", pack)
}
开发者ID:zwczou,项目名称:goserver,代码行数:11,代码来源:clientsessionload.go

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

示例10: OnSessionOpened

func (af *AuthenticationFilter) OnSessionOpened(s *netlib.Session) bool {
	timestamp := time.Now().Unix()
	h := md5.New()
	sc := s.GetSessionConfig()
	h.Write([]byte(fmt.Sprintf("%v;%v", timestamp, sc.AuthKey)))
	authPack := &protocol.SSPacketAuth{
		Timestamp: proto.Int64(timestamp),
		AuthKey:   proto.String(hex.EncodeToString(h.Sum(nil))),
	}
	proto.SetDefaults(authPack)
	s.Send(authPack)
	return true
}
开发者ID:zwczou,项目名称:goserver,代码行数:13,代码来源:authentication.go

示例11: Process

func (this *MulticastHandler) Process(s *netlib.Session, data interface{}) error {
	if mp, ok := data.(*protocol.SSPacketMulticast); ok {
		pd := mp.GetData()
		sis := mp.GetSessions()
		for _, si := range sis {
			ns := this.getSession(si)
			if ns != nil {
				ns.Send(pd, s.GetSessionConfig().IsInnerLink)
			}
		}
	}
	return nil
}
开发者ID:zwczou,项目名称:goserver,代码行数:13,代码来源:multicasthandler.go

示例12: isBlock

func (blf *BlackListFilter) isBlock(s *netlib.Session) bool {
	host, _, err := net.SplitHostPort(s.RemoteAddr())
	if err != nil {
		return true
	}

	ip := net.ParseIP(host)
	blf.lock.RLock()
	defer blf.lock.RUnlock()
	for e := blf.blacklist.Front(); e != nil; e = e.Next() {
		if e.Value.(*net.IPNet).Contains(ip) {
			return true
		}
	}
	return false
}
开发者ID:zwczou,项目名称:goserver,代码行数:16,代码来源:blacklist.go

示例13: isConnectionOk

func (ctf *ConnectionThrottleFilter) isConnectionOk(s *netlib.Session) bool {
	host, _, err := net.SplitHostPort(s.RemoteAddr())
	if err != nil {
		return false
	}

	tNow := time.Now()
	value := ctf.clients.Get(host)
	if value != nil {
		tLast := value.(time.Time)
		if tNow.Sub(tLast) < time.Duration(ctf.AllowedInterval)*time.Millisecond {
			ctf.clients.Set(host, tNow)
			return false
		}
	}

	ctf.clients.Set(host, tNow)
	return true
}
开发者ID:zwczou,项目名称:goserver,代码行数:19,代码来源:connectionthrottle.go

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

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


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