예제 #1
0
        /// <summary>
        /// Looks at all the attached content servers and determines which one has the lowest population, i.e. the one the player should play on.
        /// Returns null if no suitable servers are found (i.e. all available servers are at capacity).
        /// </summary>
        /// <returns></returns>
        public GameServerInfo <OutboundServerConnection> GetLowPopGameServer()
        {
            GameServerInfo <OutboundServerConnection> gsi = null;
            // Grab the game server with the least number of players

            GameServerInfoGroup g = OutboundServerGroups.Groups["Default"];

            if (g == null)
            {
                return(null);
            }

            List <string> addresses;
            List <string> ids;
            List <int>    ports;
            List <int>    curConnections;
            List <int>    maxConnections;

            if (!DB.Instance.Server_GetRegistrations("content", out addresses, out ids, out ports, out curConnections, out maxConnections))
            {
                gsi = g.NextConnection();
            }
            else
            {
                int   low      = 0;
                float lowRatio = 1f;
                for (int i = 0; i < ids.Count; i++)
                {
                    float ratio = (float)curConnections[i] / (float)maxConnections[i];
                    if (ratio < lowRatio)
                    {
                        lowRatio = ratio;
                        low      = i;
                    }
                }

                if (lowRatio >= 1)
                {
                    // All servers are at capacity
                    return(null);
                }

                // See if we're connected to that server
                //gsi = GetOutboundServerByServerUserID(ids[low]);

                //if (gsi == null || !gsi.IsOnline)
                {
                    // Create a temp object with latest info from DB
                    gsi          = new GameServerInfo <OutboundServerConnection>();
                    gsi.Name     = ids[low];
                    gsi.UserID   = ids[low];
                    gsi.IP       = addresses[low];
                    gsi.Port     = ports[low];
                    gsi.CurUsers = curConnections[low];
                    gsi.MaxUsers = maxConnections[low];
                }
            }

            return(gsi);
        }
예제 #2
0
        /// <summary>
        /// Gets called when a player requests to be handed off to a particular Hive.  This Base implementation simply returns the "Next" server
        /// in the indicated server group's connection list, using the group's ConnectMethod to determine the algorithm by which the "Next"
        /// connection is chosen (I.e. random or roundrobin).  This implementation only considers currently connected servers as candidates.
        /// </summary>
        /// <param name="serverGroup"></param>
        /// <returns></returns>
        protected virtual GameServerInfo <OutboundServerConnection> GetTargetServerForClusterHandoff(string serverGroup)
        {
            GameServerInfoGroup g = MyServer.OutboundServerGroups[serverGroup];

            if (g == null)
            {
                return(null);
            }
            return(g.NextConnection());;
        }