protected override int GetDefaultMapRankIndex(GameModeMap gameModeMap)
 {
     return(StatisticsManager.Instance.GetSkirmishRankForDefaultMap(gameModeMap.Map.Name, gameModeMap.Map.MaxPlayers));
 }
Beispiel #2
0
        private void HandleGameOptionsMessage(string data)
        {
            if (IsHost)
            {
                return;
            }

            string[] parts = data.Split(ProgramConstants.LAN_DATA_SEPARATOR);

            if (parts.Length != CheckBoxes.Count + DropDowns.Count + GAME_OPTION_SPECIAL_FLAG_COUNT)
            {
                AddNotice("The game host has sent an invalid game options message. This " +
                          "usually means that the game host has a different game version than you.");
                Logger.Log("Invalid game options message from host: " + data);
                return;
            }

            int randomSeed = Conversions.IntFromString(parts[parts.Length - GAME_OPTION_SPECIAL_FLAG_COUNT], -1);

            if (randomSeed == -1)
            {
                return;
            }

            RandomSeed = randomSeed;

            string mapSHA1  = parts[parts.Length - (GAME_OPTION_SPECIAL_FLAG_COUNT - 1)];
            string gameMode = parts[parts.Length - (GAME_OPTION_SPECIAL_FLAG_COUNT - 2)];

            GameModeMap gameModeMap = GameModeMaps.Find(gmm => gmm.GameMode.Name == gameMode && gmm.Map.SHA1 == mapSHA1);

            if (gameModeMap == null)
            {
                AddNotice("The game host has selected a map that doesn't exist on your " +
                          "installation. The host needs to change the map or you won't be able to play.");
                ChangeMap(null);
                return;
            }

            if (GameModeMap != gameModeMap)
            {
                ChangeMap(gameModeMap);
            }

            int frameSendRate = Conversions.IntFromString(parts[parts.Length - (GAME_OPTION_SPECIAL_FLAG_COUNT - 3)], FrameSendRate);

            if (frameSendRate != FrameSendRate)
            {
                FrameSendRate = frameSendRate;
                AddNotice("The game host has changed FrameSendRate (order lag) to " + frameSendRate);
            }

            bool removeStartingLocations = Convert.ToBoolean(Conversions.IntFromString(
                                                                 parts[parts.Length - (GAME_OPTION_SPECIAL_FLAG_COUNT - 4)], Convert.ToInt32(RemoveStartingLocations)));

            SetRandomStartingLocations(removeStartingLocations);

            for (int i = 0; i < CheckBoxes.Count; i++)
            {
                GameLobbyCheckBox chkBox = CheckBoxes[i];

                bool oldValue = chkBox.Checked;
                chkBox.Checked = Conversions.IntFromString(parts[i], -1) > 0;

                if (chkBox.Checked != oldValue)
                {
                    if (chkBox.Checked)
                    {
                        AddNotice("The game host has enabled " + chkBox.Text);
                    }
                    else
                    {
                        AddNotice("The game host has disabled " + chkBox.Text);
                    }
                }
            }

            for (int i = 0; i < DropDowns.Count; i++)
            {
                int index = Conversions.IntFromString(parts[CheckBoxes.Count + i], -1);

                GameLobbyDropDown dd = DropDowns[i];

                if (index < 0 || index >= dd.Items.Count)
                {
                    return;
                }

                int oldValue = dd.SelectedIndex;
                dd.SelectedIndex = index;

                if (index != oldValue)
                {
                    string ddName = dd.OptionName;
                    if (dd.OptionName == null)
                    {
                        ddName = dd.Name;
                    }

                    AddNotice("The game host has set " + ddName + " to " + dd.SelectedItem.Text);
                }
            }
        }