BF2Statistics.ServerSettings.GetValue C# (CSharp) Method

GetValue() public method

Method for returning the string value of a settings item
Thrown if the named item doesnt exist
public GetValue ( string Name ) : string
Name string The name of the config item
return string
        public string GetValue(string Name)
        {
            try {
                return Items[Name];
            }
            catch (KeyNotFoundException) {
                Program.ErrorLog.Write("WARNING: [SettingsParser]: Server Setting \"{0}\" Not Found in ServerSettings.con", Name);
                throw;
            }
        }

Same methods

ServerSettings::GetValue ( string Name, string DefaultValue ) : string

Usage Example

Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="UseGlobalSettings">
        /// If true, the global settings file will be used
        /// instead of the Selected mods settings file
        /// </param>
        public ServerSettingsForm(bool UseGlobalSettings)
        {
            InitializeComponent();
            this.UseGlobalSettings = UseGlobalSettings;

            // Parse settings file, and fill in form values
            try
            {
                // Load Settings, and set for title
                if (UseGlobalSettings)
                {
                    this.Settings = new ServerSettings(Path.Combine(Program.RootPath, "Python", "GlobalServerSettings.con"));
                    this.Text     = "Global Server Settings";
                }
                else
                {
                    this.Settings = MainForm.SelectedMod.ServerSettings;
                    this.Text     = MainForm.SelectedMod.Title + " Server Settings";
                }

                // General
                ServerNameBox.Text            = Settings.GetValue("serverName", "Default Server Name");
                ServerPasswordBox.Text        = Settings.GetValue("password", "");
                ServerIpBox.Text              = Settings.GetValue("serverIP", "");
                ServerPortBox.Value           = Int32.Parse(Settings.GetValue("serverPort", "16567"));
                GamespyPortBox.Value          = Int32.Parse(Settings.GetValue("gameSpyPort", "29900"));
                ServerWelcomeBox.Text         = Settings.GetValue("welcomeMessage", "");
                AutoBalanceBox.Checked        = (Int32.Parse(Settings.GetValue("autoBalanceTeam", "0")) == 1);
                EnablePublicServerBox.Checked = (Int32.Parse(Settings.GetValue("internet", "0")) == 1);
                EnablePunkBuster.Checked      = (Int32.Parse(Settings.GetValue("punkBuster", "0")) == 1);
                RoundsPerMapBox.Value         = Int32.Parse(Settings.GetValue("roundsPerMap", "3"));
                PlayersToStartSlider.Value    = Int32.Parse(Settings.GetValue("numPlayersNeededToStart", "2"));
                MaxPlayersBar.Value           = Int32.Parse(Settings.GetValue("maxPlayers", "16"));
                TicketRatioBar.Value          = Int32.Parse(Settings.GetValue("ticketRatio", "200"));
                ScoreLimitBar.Value           = Int32.Parse(Settings.GetValue("scoreLimit", "0"));
                TeamRatioBar.Value            = Int32.Parse(Settings.GetValue("teamRatioPercent", "50"));

                // Time settings
                TimeLimitBar.Value        = Int32.Parse(Settings.GetValue("timeLimit", "0"));
                SpawnTimeBar.Value        = Int32.Parse(Settings.GetValue("spawnTime", "15"));
                ManDownBar.Value          = Int32.Parse(Settings.GetValue("manDownTime", "15"));
                StartDelayBar.Value       = Int32.Parse(Settings.GetValue("startDelay", "15"));
                EndDelayBar.Value         = Int32.Parse(Settings.GetValue("endDelay", "15"));
                EORBar.Value              = Int32.Parse(Settings.GetValue("endOfRoundDelay", "15"));
                NotEnoughPlayersBar.Value = Int32.Parse(Settings.GetValue("notEnoughPlayersRestartDelay", "15"));
                TimeB4RestartMapBar.Value = Int32.Parse(Settings.GetValue("timeBeforeRestartMap", "45"));

                // Friendly Fire Settings
                PunishTeamKillsBox.Checked = (Int32.Parse(Settings.GetValue("tkPunishEnabled", "1")) == 1);
                FriendlyFireBox.Checked    = (Int32.Parse(Settings.GetValue("friendlyFireWithMines", "0")) == 1);
                PunishDefaultBox.Checked   = (Int32.Parse(Settings.GetValue("tkPunishByDefault", "0")) == 1);
                TksBeforeKickBox.Value     = Int32.Parse(Settings.GetValue("tkNumPunishToKick", "3"));
                SoldierFFBar.Value         = Int32.Parse(Settings.GetValue("soldierFriendlyFire", "100"));
                VehicleFFBar.Value         = Int32.Parse(Settings.GetValue("vehicleFriendlyFire", "100"));
                SoldierSplashFFBar.Value   = Int32.Parse(Settings.GetValue("soldierSplashFriendlyFire", "100"));
                VehicleSplashFFBar.Value   = Int32.Parse(Settings.GetValue("vehicleSplashFriendlyFire", "100"));

                // Voip
                EnableVoip.Checked       = (Int32.Parse(Settings.GetValue("voipEnabled", "1")) == 1);
                EnableRemoteVoip.Checked = (Int32.Parse(Settings.GetValue("voipServerRemote", "0")) == 1);
                VoipBF2ClientPort.Value  = Int32.Parse(Settings.GetValue("voipBFClientPort", "55123"));
                VoipBF2ServerPort.Value  = Int32.Parse(Settings.GetValue("voipBFServerPort", "55124"));
                VoipServerPort.Value     = Int32.Parse(Settings.GetValue("voipServerPort", "55125"));
                RemoteVoipIpBox.Text     = Settings.GetValue("voipServerRemoteIP", "");
                VoipPasswordBox.Text     = Settings.GetValue("voipSharedPassword", "");
                VoipQualityBar.Value     = Int32.Parse(Settings.GetValue("voipQuality", "3"));

                // Voting Settings
                EnableVotingBox.Checked     = (Int32.Parse(Settings.GetValue("votingEnabled", "1")) == 1);
                EnableTeamVotingBox.Checked = (Int32.Parse(Settings.GetValue("teamVoteOnly", "1")) == 1);
                VoteTimeBar.Value           = Int32.Parse(Settings.GetValue("voteTime", "90"));
                PlayersVotingBar.Value      = Int32.Parse(Settings.GetValue("minPlayersForVoting", "2"));

                // Demo & Urls
                EnableAutoRecord.Checked = (Int32.Parse(Settings.GetValue("autoRecord", "0")) == 1);
                DemoQualityBar.Value     = Int32.Parse(Settings.GetValue("demoQuality", "5"));
                DemoIndexUrlBox.Text     = Settings.GetValue("demoIndexURL", "http://");
                DemoDownloadBox.Text     = Settings.GetValue("demoDownloadURL", "http://");
                DemoHookBox.Text         = Settings.GetValue("autoDemoHook", "adminutils/demo/rotate_demo.exe");
                CLogoUrlBox.Text         = Settings.GetValue("communityLogoURL", "");
                SLogoUrlBox.Text         = Settings.GetValue("sponsorLogoURL", "");

                // Misc Settings
                AllowNATNagotiation.Checked = (Int32.Parse(Settings.GetValue("allowNATNegotiation", "0")) == 1);
                AllowFreeCam.Checked        = (Int32.Parse(Settings.GetValue("allowFreeCam", "0")) == 1);
                AllowNoseCam.Checked        = (Int32.Parse(Settings.GetValue("allowNoseCam", "1")) == 1);
                AllowExtViews.Checked       = (Int32.Parse(Settings.GetValue("allowExternalViews", "1")) == 1);
                HitIndicatorEnabled.Checked = (Int32.Parse(Settings.GetValue("hitIndicator", "1")) == 1);
                RadioSpamIntBox.Value       = Int32.Parse(Settings.GetValue("radioSpamInterval", "6"));
                RadioMaxSpamBox.Value       = Int32.Parse(Settings.GetValue("radioMaxSpamFlagCount", "6"));
                RadioBlockTimeBar.Value     = Int32.Parse(Settings.GetValue("radioBlockedDurationTime", "30"));

                // Bot Settings
                GetBotSettings();
            }
            catch (Exception e)
            {
                this.Load += (s, ea) => this.Close();
                MessageBox.Show(e.Message, "Server Settings File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }