Пример #1
0
        public static void OnStartServerSessionMessageReceived(StartServerSessionMessage message)
        {
            if (GameModeClusterManager.m_sessionClusters.ContainsKey(message.SessionId))
            {
                throw new Exception("GameModeClusterManager.onStartSessionMessageReceived: session already started!");
            }

            GameModeCluster gameModeCluster = GameModeClusterManager.GetFastestCluster();

            if (gameModeCluster != null)
            {
                GameModeClusterManager.m_sessionClusters.Add(message.SessionId, gameModeCluster);
                gameModeCluster.SendMessage(message);
            }
            else
            {
                if (message.BindRequestMessage != null)
                {
                    ServerRequestManager.SendResponse(new BindServerSocketResponseMessage(), message.BindRequestMessage);
                }
                ServerMessageManager.SendMessage(new StartServerSessionFailedMessage
                {
                    SessionId = message.SessionId
                }, message.Sender);
            }
        }
Пример #2
0
        private static GameModeCluster GetFastestCluster()
        {
            GameModeCluster fastestCluster = null;

            for (int i = 0, fastestClusterTime = 0x7FFFFFFF; i < GameModeClusterManager.m_clusters.Length; i++)
            {
                GameModeCluster instance    = GameModeClusterManager.m_clusters[i];
                long            executeTime = instance.GetAverageMessageProcessSpeed();

                if (executeTime <= 2000L && (fastestCluster == null || executeTime < fastestClusterTime))
                {
                    fastestCluster     = instance;
                    fastestClusterTime = (int)executeTime;
                }
            }

            return(fastestCluster);
        }