package main

import (
	"mongo.games.com/goserver/core/netlib"
	"mongo.games.com/goserver/srvlib"
	"mongo.games.com/goserver/srvlib/protocol"
)

var rankSession *netlib.Session

func init() {
	srvlib.ServerSessionMgrSington.AddListener(new(RankSessionMgr))
}

type RankSessionMgr struct {
}

func (r *RankSessionMgr) OnRegiste(s *netlib.Session) {
	attr := s.GetAttribute(srvlib.SessionAttributeServerInfo)
	if attr != nil {
		if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
			if srvInfo.GetType() == srvlib.RankServerType {
				rankSession = s
			}
		}
	}
}

func (r *RankSessionMgr) OnUnregiste(s *netlib.Session) {
	attr := s.GetAttribute(srvlib.SessionAttributeServerInfo)
	if attr != nil {
		if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil {
			if srvInfo.GetType() == srvlib.RankServerType {
				rankSession = nil
			}
		}
	}
}
