예제 #1
0
        public BaseServer()
        {
            DrawAscii();

            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();

            socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Config = new XmlConfig(configFilePath);
            Config.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            if (!File.Exists(configFilePath))
            {
                Config.Create();
                Logger.Info("config file created & loaded !");
            }
            else
            {
                Config.Load();
                Logger.Info("config file loaded !");
            }

            GCSettings.LatencyMode = GCLatencyMode.Batch;

            IOTaskPool = new CyclicTaskRunner(100, "Server");
            IOTaskPool.Start();
        }
예제 #2
0
        public virtual void UpdateConfigFiles()
        {
            logger.Info("Recreate server config file ...");

            if (File.Exists(ConfigFilePath))
            {
                logger.Info("Update {0} file", ConfigFilePath);

                Config = new XmlConfig(ConfigFilePath);
                Config.AddAssemblies(LoadedAssemblies.Values.ToArray());
                Config.Load();
                Config.Create(true);
            }
            else
            {
                logger.Info("Create {0} file", ConfigFilePath);

                Config = new XmlConfig(ConfigFilePath);
                Config.AddAssemblies(LoadedAssemblies.Values.ToArray());
                Config.Create();
            }

            logger.Info("Recreate plugins config files ...", ConfigFilePath);

            PluginManager = PluginManager.Instance;
            PluginManager.Instance.LoadAllPlugins();

            foreach (var plugin in PluginManager.GetPlugins().Select(entry => entry.Plugin).OfType <PluginBase>())
            {
                if (!plugin.UseConfig || !plugin.AllowConfigUpdate)
                {
                    continue;
                }

                var update = File.Exists(plugin.GetConfigPath());

                if (!update)
                {
                    logger.Info("Create '{0}' config file => '{1}'", plugin.Name, Path.GetFileName(plugin.GetConfigPath()));
                }

                plugin.LoadConfig();

                if (!update)
                {
                    continue;
                }

                logger.Info("Update '{0}' config file => '{1}'", plugin.Name, Path.GetFileName(plugin.GetConfigPath()));
                plugin.Config.Create(true);
            }

            logger.Info("All config files were correctly updated/created ! Shutdown ...");
            Thread.Sleep(TimeSpan.FromSeconds(2.0));
            Environment.Exit(0);
        }
예제 #3
0
        public static void LoadSettings()
        {
            m_config = new XmlConfig(ConfigPath);
            m_config.AddAssembly(typeof(Settings).Assembly);

            if (!File.Exists(ConfigPath))
            {
                m_config.Create();
            }
            else
            {
                m_config.Load();
            }
        }
예제 #4
0
        public static void Initialize()
        {
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();

            ConnectedClients = new List <SimpleClient>();

            logger.Info("Initializing Configuration !");

            Config = new XmlConfig(configFilePath);
            Config.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name).Values.ToArray());

            if (!File.Exists(configFilePath))
            {
                Config.Create();
                logger.Info("Config file created !");
            }
            else
            {
                Config.Load();
                //Config.Save();
            }
            logger.Info("Loading protocol messages !");
            MessageReceiver.Initialize();

            logger.Info("Loading handlers !");
            PacketManager.Initialize(Assembly.GetExecutingAssembly());

            logger.Info("Loading Database !");
            DBAccessor = new DatabaseAccessor(DatabaseConfiguration);
            DBAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
            DBAccessor.Initialize();
            DBAccessor.OpenConnection();
            DataManagerAllocator.Assembly   = System.Reflection.Assembly.GetExecutingAssembly();
            DatabaseManager.DefaultDatabase = DBAccessor.Database;

            logger.Info("Loading database features !");
            InitManager = Singleton <InitializationManager> .Instance;
            InitManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            InitManager.Initialize(InitializationPass.Database);
            InitManager.InitializeAll();
        }
예제 #5
0
        public virtual void LoadConfig()
        {
            if (!UseConfig)
            {
                return;
            }

            var configPath = GetConfigPath();

            Config = new XmlConfig(configPath);
            Config.AddAssembly(GetType().Assembly);

            if (File.Exists(configPath))
            {
                Config.Load();
            }
            else
            {
                Config.Create();
            }
        }
예제 #6
0
        public void Initialize()
        {
            ConsoleUtils.WriteMessageInfo("Initializing Configuration !");

            Config = new XmlConfig(configFilePath);
            Config.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name).Values.ToArray());

            if (!File.Exists(configFilePath))
            {
                Config.Create();
                ConsoleUtils.WriteMessageInfo("Config file created !");
            }
            else
            {
                Config.Load();
            }


            ConsoleUtils.WriteMessageInfo("Loading protocol messages !");
            MessageReceiver.Initialize();

            ConsoleUtils.WriteMessageInfo("Loading handlers !");
            PacketManager.Initialize(Assembly.GetExecutingAssembly());

            ConsoleUtils.WriteMessageInfo("Loading Database !");
            DBAccessor = new DatabaseAccessor(DatabaseConfiguration);
            DBAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
            DBAccessor.Initialize();
            DBAccessor.OpenConnection();
            DataManagerAllocator.Assembly   = System.Reflection.Assembly.GetExecutingAssembly();
            DatabaseManager.DefaultDatabase = DBAccessor.Database;

            ConsoleUtils.WriteMessageInfo("Loading database features !");
            this.InitManager = Singleton <InitializationManager> .Instance;
            this.InitManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            this.InitManager.Initialize(InitializationPass.Database);
            InitManager.InitializeAll();
        }
예제 #7
0
        public virtual void Initialize()
        {
            InstanceAsBase = this;
            Initializing   = true;

            Version = ((AssemblyInformationalVersionAttribute)System.Reflection.Assembly.GetExecutingAssembly()
                       .GetCustomAttributes <AssemblyInformationalVersionAttribute>().FirstOrDefault())
                      .InformationalVersion;

            /* Initialize Logger */
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();
            logger = LogManager.GetCurrentClassLogger();

            if (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
                TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;
                Contract.ContractFailed += OnContractFailed;
            }
            else
            {
                logger.Warn("Exceptions not handled cause Debugger is attatched");
            }

            PreLoadReferences(Assembly.GetCallingAssembly());
            LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name);
            AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

            if (Environment.GetCommandLineArgs().Contains("-config"))
            {
                UpdateConfigFiles();
            }

            ConsoleBase.DrawAsciiLogo();
            Console.WriteLine();

            InitializeGarbageCollector();

            logger.Info("Initializing Configuration...");
            /* Initialize Config File */
            Config = new XmlConfig(ConfigFilePath);
            Config.AddAssemblies(LoadedAssemblies.Values.ToArray());

            if (!File.Exists(ConfigFilePath))
            {
                Config.Create();
                logger.Info("Config file created");
            }
            else
            {
                Config.Load();
            }

            logger.Info("Initialize Task Pool");
            IOTaskPool = new BenchmarkedTaskPool(IOTaskInterval, "IO Task Pool");

            CommandManager = CommandManager.Instance;
            CommandManager.RegisterAll(Assembly.GetExecutingAssembly());

            logger.Info("Initializing Network Interfaces...");
            ClientManager = ClientManager.Instance;
            ClientManager.Initialize(CreateClient);

            if (Settings.InactivityDisconnectionTime.HasValue)
            {
                IOTaskPool.CallPeriodically(Settings.InactivityDisconnectionTime.Value / 4 * 1000, DisconnectAfkClient);
            }

            ClientManager.ClientConnected    += OnClientConnected;
            ClientManager.ClientDisconnected += OnClientDisconnected;

            logger.Info("Register Plugins...");
            // the plugins add them themself to the initializer
            InitializationManager = InitializationManager.Instance;
            InitializationManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());

            PluginManager                = PluginManager.Instance;
            PluginManager.PluginAdded   += OnPluginAdded;
            PluginManager.PluginRemoved += OnPluginRemoved;

            logger.Info("Loading Plugins...");
            PluginManager.Instance.LoadAllPlugins();

            if (IsExceptionLoggerEnabled)
            {
                ExceptionLogger         = new RavenClient(ExceptionLoggerDSN);
                ExceptionLogger.Release = Version;
#if DEBUG
                ExceptionLogger.Environment = "DEBUG";
#else
                ExceptionLogger.Environment = "RELEASE";
#endif
            }
        }
예제 #8
0
        public static void Main()
        {
            Console.WriteLine("Load {0}...", ConfigFile);
            m_config = new XmlConfig(ConfigFile);
            m_config.AddAssembly(Assembly.GetExecutingAssembly());

            if (!File.Exists(ConfigFile))
            {
                m_config.Create();
            }
            else
            {
                m_config.Load();
            }

            Console.WriteLine("Initializing Database...");
            m_databaseAccessor = new DatabaseAccessor(DatabaseConfiguration);
            m_databaseAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
            m_databaseAccessor.Initialize();

            Console.WriteLine("Opening Database...");
            m_databaseAccessor.OpenConnection();
            DataManager.DefaultDatabase = m_databaseAccessor.Database;

            Console.WriteLine("Loading texts...");
            TextManager.Instance.Initialize();
            TextManager.Instance.SetDefaultLanguage(SecondaryLanguage);

            Console.WriteLine("Loading effects...");
            EffectManager.Instance.Initialize();

            Console.WriteLine("Loading spells...");
            SpellManager.Instance.Initialize();


            while (true)
            {
                Console.Write(">");
                var pattern = Console.ReadLine();
                try
                {
                    if (pattern.StartsWith("target:"))
                    {
                        var target = pattern.Remove(0, "target:".Length);

                        if (!target.Any())
                        {
                            var targets = SpellManager.Instance.GetSpellTemplates()
                                          .SelectMany(x => SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0]).Effects.SelectMany(y => y.TargetMask.Split(','))).Select(z => z[0]).Distinct();

                            foreach (var mask in targets)
                            {
                                Console.WriteLine(mask);
                            }
                        }

                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.TargetMask.Contains(target))))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }

                    if (pattern.StartsWith("trigger:"))
                    {
                        var trigger = pattern.Remove(0, "trigger:".Length);

                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.Triggers.Split('|').Any(z => z == trigger))))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }

                    if (pattern.StartsWith("zone:"))
                    {
                        var zone = pattern.Remove(0, "zone:".Length);

                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.ZoneShape.ToString() == zone)))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }

                    if (pattern.StartsWith("delay"))
                    {
                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.Delay != 0)))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }

                    if (pattern.StartsWith("priority"))
                    {
                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.Priority != 0)))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }
                    if (pattern.StartsWith("group"))
                    {
                        foreach (
                            var spell in
                            SpellManager.Instance.GetSpellTemplates()
                            .Where(
                                x =>
                                SpellManager.Instance.GetSpellLevel((int)x.SpellLevelsIds[0])
                                .Effects.Any(y => y.Group != 0)))
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Name, spell.Id);
                        }
                    }
                    if (pattern.StartsWith("@"))
                    {
                        pattern = pattern.Remove(0, 1);

                        var spells = SpellManager.Instance.GetSpellLevels()
                                     .Where(x => x.Effects.Any(y => y.Id == int.Parse(pattern)));

                        foreach (var spell in spells.Distinct())
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Spell.Name, spell.SpellId);
                        }
                    }
                    if (pattern.StartsWith("casted:"))
                    {
                        var spellId = int.Parse(pattern.Remove(0, "casted:".Length));

                        var spells = SpellManager.Instance.GetSpellLevels()
                                     .Where(x => x.Effects.Any(y => (y.EffectId == EffectsEnum.Effect_TriggerBuff || y.EffectId == EffectsEnum.Effect_TriggerBuff_793 ||
                                                                     y.EffectId == EffectsEnum.Effect_CastSpell_1160 || y.EffectId == EffectsEnum.Effect_CastSpell_1017) && y.DiceNum == spellId));

                        foreach (var spell in spells.Distinct())
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Spell.Name, spell.SpellId);
                        }
                    }
                    if (pattern.StartsWith("state:"))
                    {
                        var stateId = int.Parse(pattern.Remove(0, "state:".Length));

                        var spells = SpellManager.Instance.GetSpellLevels()
                                     .Where(x => x.Effects.Any(y => y.EffectId == EffectsEnum.Effect_AddState && y.Value == stateId));

                        foreach (var spell in spells.Distinct())
                        {
                            Console.WriteLine("Spell:{0} ({1})", spell.Spell.Name, spell.SpellId);
                        }
                    }

                    var critical = pattern.EndsWith("!");
                    if (critical)
                    {
                        pattern = pattern.Remove(pattern.Length - 1, 1);
                    }

                    foreach (SpellTemplate spell in FindSpells(pattern))
                    {
                        if (spell == null)
                        {
                            Console.WriteLine("Spell not found");
                        }
                        else
                        {
                            ExploreSpell(spell, FindPatternSpellLevel(pattern), critical);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }