using ActorCore;
using Server.Net;

namespace Server
{
    public static class UserSessionsInfo
    {
        private static UserNetActor _userNetActor;
        
        /// <summary>
        /// 获取已经绑定的用户连接数量
        /// </summary>
        /// <returns></returns>
        public static int GetBindSessionCount()
        {
            if (UserSessionsManager.Instance == null)
            {
                return 0;
            }
            return UserSessionsManager.Instance.Count;
        }

        /// <summary>
        /// 获取所有用户连接数据
        /// </summary>
        /// <returns></returns>
        public static int GetAllSessionCount()
        {
            int cnt = 0;
            if (NetManager.isStart)  //club gameCenter 使用了这个
            {
                cnt += NetManager.Instance.ConnectCount;
            }

            if (GameNetManager.IsStart)  //游戏用的这个
            {
                cnt += GameNetManager.Instance.ConnectCount;
            }

            if (_userNetActor == null && ActorManager.Instance != null)
            {
                _userNetActor = ActorManager.Instance.Get(ActorTypeId.UserNet) as UserNetActor;
            }

            if (_userNetActor != null)
            {
                cnt += _userNetActor.ConnectCnt;
            }

            return cnt;
        }
    }
}