當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.GetSessionConfig方法代碼示例

本文整理匯總了Golang中github.com/idealeak/goserver/core/netlib.Session.GetSessionConfig方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.GetSessionConfig方法的具體用法?Golang Session.GetSessionConfig怎麽用?Golang Session.GetSessionConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/idealeak/goserver/core/netlib.Session的用法示例。


在下文中一共展示了Session.GetSessionConfig方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

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

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

示例7: OnSessionClosed

func (this *SessionHandlerServiceRegiste) OnSessionClosed(s *netlib.Session) {
	sc := s.GetSessionConfig()
	if !sc.IsClient {
		srvlib.ServiceMgr.ClearServiceBySession(s)
	}
}
開發者ID:zwczou,項目名稱:goserver,代碼行數:6,代碼來源:serverserviceregiste.go

示例8: NewSessionId

func NewSessionId(s *netlib.Session) SessionId {
	sc := s.GetSessionConfig()
	id := int64(sc.AreaId)<<SessionIdSrvAreaOffset | int64(sc.Type)<<SessionIdSrvTypeOffset | int64(sc.Id)<<SessionIdSrvIdOffset | int64(s.Id)
	return SessionId(id)
}
開發者ID:zwczou,項目名稱:goserver,代碼行數:5,代碼來源:sessionid.go


注:本文中的github.com/idealeak/goserver/core/netlib.Session.GetSessionConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。