Example #1
0
        private void InitialSetup() {
            if (Game != null) {
                IsLoadingSavingConnectionConfig = true;

                AssignEventHandlers();

                // Assume full access until we're told otherwise.
                Layer.Initialize(Parent, this);

                // I may move these events to within Layer, depends on the end of the restructure.
                Layer.LayerOnline += new PRoConLayer.LayerEmptyParameterHandler(Layer_LayerOnline);
                Layer.LayerOffline += new PRoConLayer.LayerEmptyParameterHandler(Layer_LayerOffline);
                Layer.AccountPrivileges.AccountPrivilegeAdded += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeAdded);
                Layer.AccountPrivileges.AccountPrivilegeRemoved += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeRemoved);

                foreach (AccountPrivilege apPriv in Layer.AccountPrivileges) {
                    apPriv.AccountPrivilegesChanged += new AccountPrivilege.AccountPrivilegesChangedHandler(item_AccountPrivilegesChanged);
                }

                Privileges = new CPrivileges(CPrivileges.FullPrivilegesFlags);
                EventsLogging = new EventCaptures(this);
                Console = new ConnectionConsole(this);
                PunkbusterConsole = new PunkbusterConsole(this);
                ChatConsole = new ChatConsole(this);
                PluginConsole = new PluginConsole(this);
                MapGeometry = new MapGeometry(this);
                MapGeometry.MapZones.MapZoneAdded += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneAdded);
                MapGeometry.MapZones.MapZoneChanged += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneChanged);
                MapGeometry.MapZones.MapZoneRemoved += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneRemoved);

                if (CurrentServerInfo == null) {
                    CurrentServerInfo = new CServerInfo();
                }

                ListSettings = new ListsSettings(this);
                ServerSettings = new ServerSettings(this);
                PlayerListSettings = new PlayerListSettings();
                PlayerList = new PlayerDictionary();
                TeamNameList = new List<CTeamName>();
                MapListPool = new NotificationList<CMap>();
                ReservedSlotList = new NotificationList<string>();
                Variables = new VariableDictionary();
                SV_Variables = new VariableDictionary();
                Reasons = new NotificationList<string>();
                FullVanillaBanList = new List<CBanInfo>();
                FullTextChatModerationList = new TextChatModerationDictionary();
                Weapons = new WeaponDictionary();
                Specializations = new SpecializationDictionary();

                if (Regex.Match(HostName, @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Success == true) {
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(HostName));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(HostName));
                }
                else {
                    IPAddress ipServer = FrostbiteConnection.ResolveHostName(HostName);
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(ipServer.ToString()));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(ipServer.ToString()));
                }

                Console.Logging = Parent.OptionsSettings.ConsoleLogging;
                EventsLogging.Logging = Parent.OptionsSettings.EventsLogging;
                ChatConsole.Logging = Parent.OptionsSettings.ChatLogging;
                PluginConsole.Logging = Parent.OptionsSettings.PluginLogging;

                //this.m_blLoadingSavingConnectionConfig = true;

                if (CurrentServerInfo.GameMod == GameMods.None) {
                    ExecuteConnectionConfig(Game.GameType + ".def", 0, null, false);
                }
                else {
                    ExecuteConnectionConfig(Game.GameType + "." + CurrentServerInfo.GameMod + ".def", 0, null, false);
                }

                // load override global_vars.def
                ExecuteGlobalVarsConfig("global_vars.def", 0, null);

                ExecuteConnectionConfig("reasons.cfg", 0, null, false);

                lock (Parent) {
                    if (Username.Length == 0 || Parent.OptionsSettings.LayerHideLocalPlugins == false) {
                        CompilePlugins(Parent.OptionsSettings.PluginPermissions);
                    }
                }

                if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                    ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, false);
                }

                //this.m_blLoadingSavingConnectionConfig = false;

                // this.ManuallyDisconnected = true;

                // this.ConnectionError = false;

                BeginLoginSequence();

                if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                    ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, true);
                }

                IsLoadingSavingConnectionConfig = false;
            }
        }
Example #2
0
        private void InitialSetup() {
            if (Game != null) {
                IsLoadingSavingConnectionConfig = true;

                AssignEventHandlers();

                // Assume full access until we're told otherwise.
                Layer.Initialize(Parent, this);

                // I may move these events to within Layer, depends on the end of the restructure.
                Layer.LayerStarted += Layer_LayerOnline;
                Layer.LayerShutdown += Layer_LayerOffline;
                Layer.AccountPrivileges.AccountPrivilegeAdded += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeAdded);
                Layer.AccountPrivileges.AccountPrivilegeRemoved += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeRemoved);

                foreach (AccountPrivilege apPriv in Layer.AccountPrivileges) {
                    apPriv.AccountPrivilegesChanged += new AccountPrivilege.AccountPrivilegesChangedHandler(item_AccountPrivilegesChanged);
                }

                Privileges = new CPrivileges(CPrivileges.FullPrivilegesFlags);
                EventsLogging = new EventCaptures(this);
                Console = new ConnectionConsole(this);
                PunkbusterConsole = new PunkbusterConsole(this);
                ChatConsole = new ChatConsole(this);
                PluginConsole = new PluginConsole(this);
                MapGeometry = new MapGeometry(this);
                MapGeometry.MapZones.MapZoneAdded += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneAdded);
                MapGeometry.MapZones.MapZoneChanged += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneChanged);
                MapGeometry.MapZones.MapZoneRemoved += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneRemoved);

                if (CurrentServerInfo == null) {
                    CurrentServerInfo = new CServerInfo();
                }

                ListSettings = new ListsSettings(this);
                ServerSettings = new ServerSettings(this);
                PlayerListSettings = new PlayerListSettings();
                PlayerList = new PlayerDictionary();
                TeamNameList = new List<CTeamName>();
                MapListPool = new NotificationList<CMap>();
                ReservedSlotList = new NotificationList<string>();
                SpectatorList = new NotificationList<string>();
                Variables = new VariableDictionary();
                SV_Variables = new VariableDictionary();
                Reasons = new NotificationList<string>();
                FullVanillaBanList = new List<CBanInfo>();
                FullTextChatModerationList = new TextChatModerationDictionary();
                Weapons = new WeaponDictionary();
                Specializations = new SpecializationDictionary();

                if (Regex.Match(HostName, @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Success == true) {
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(HostName));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(HostName));
                }
                else {
                    IPAddress ipServer = FrostbiteConnection.ResolveHostName(HostName);
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(ipServer.ToString()));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(ipServer.ToString()));
                }

                Console.Logging = Parent.OptionsSettings.ConsoleLogging;
                EventsLogging.Logging = Parent.OptionsSettings.EventsLogging;
                ChatConsole.Logging = Parent.OptionsSettings.ChatLogging;
                PluginConsole.Logging = Parent.OptionsSettings.PluginLogging;

                //this.m_blLoadingSavingConnectionConfig = true;

                if (CurrentServerInfo.GameMod == GameMods.None) {
                    ExecuteConnectionConfig(Game.GameType + ".def", 0, null, false);
                }
                else {
                    ExecuteConnectionConfig(Game.GameType + "." + CurrentServerInfo.GameMod + ".def", 0, null, false);
                }

                // load override global_vars.def
                ExecuteGlobalVarsConfig("global_vars.def", 0, null);

                ExecuteConnectionConfig("reasons.cfg", 0, null, false);

                lock (Parent) {
                    if (Username.Length == 0 || Parent.OptionsSettings.LayerHideLocalPlugins == false) {
                        CompilePlugins(Parent.OptionsSettings.PluginPermissions);
                    }
                }

                string configDirectoryPath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"), FileHostNamePort);
                string oldConfigFilePath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"), string.Format("{0}.cfg", FileHostNamePort));

                if (File.Exists(oldConfigFilePath) == false && Directory.Exists(configDirectoryPath) == true) {
                    string[] pluginConfigPaths = Directory.GetFiles(configDirectoryPath, "*.cfg");

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                        foreach (string pluginConfigPath in pluginConfigPaths) {
                            ExecuteConnectionConfig(pluginConfigPath, 0, null, false);
                        }
                    }

                    BeginLoginSequence();

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                        foreach (string pluginConfigPath in pluginConfigPaths) {
                            ExecuteConnectionConfig(pluginConfigPath, 0, null, true);
                        }
                    }

                    IsLoadingSavingConnectionConfig = false;
                }
                else {
                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                        ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, false);
                    }

                    BeginLoginSequence();

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                        ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, true);
                    }

                    IsLoadingSavingConnectionConfig = false;
                    SaveConnectionConfig();

                    try
                    {
                        if (Directory.Exists(configDirectoryPath) == true && File.Exists(Path.Combine(configDirectoryPath, string.Format("{0}.cfg", FileHostNamePort))) == true)
                        {
                            try
                            {
                                if (File.Exists(oldConfigFilePath) == true) {
                                    File.Delete(oldConfigFilePath);
                                }
                            }
                            catch (Exception e) {
                                FrostbiteConnection.LogError("RemoveOldConfig", String.Empty, e);
                            }
                        }
                    }
                    catch (Exception e) {
                        FrostbiteConnection.LogError("MigrateConfig", "Error writing new config structure during migration", e);
                    }
                }

            }
        }