Exemplo n.º 1
0
        /// <summary>
        /// Loads all listed files that contains weaponary information
        /// </summary>
        protected override void Load()
        {
            WeaponarySettings section = (WeaponarySettings)ConfigurationManager.GetSection("Saga.Factory.Weaponary");

            if (section != null)
            {
                foreach (FactoryFileElement element in section.FolderItems)
                {
                    WriteLine("WeaponFactory", "Loading weapon information from: {0} using format {1}", element.Path, element.Reader);
                    LoadParameterizedStreamContent(Saga.Structures.Server.SecurePath(element.Path), element.Reader);
                }
            }
            else
            {
                WriteWarning("XmlSections", "Section {0} was not found", "Saga.Factory.Weaponary");
            }
        }
Exemplo n.º 2
0
        private static void FirstRunConfiguration()
        {
            IPAddress     gatewayip           = IPAddress.Loopback;
            int           gatewayport         = 64003;
            IPAddress     mapip               = IPAddress.Loopback;
            byte          worldid             = 0;
            int           mapport             = 64002;
            int           playerlimit         = 60;
            string        databaseusername    = "******";
            string        databasepassword    = "******";
            uint          dbport              = 3306;
            int           cexprates           = 1;
            int           jexprates           = 1;
            int           wexprates           = 1;
            int           droprates           = 1;
            string        databasename        = "saga_world";
            string        dbhost              = "localhost";
            string        dbprovider          = "Saga.Map.Data.Mysql.dll, Saga.Map.Data.Mysql.MysqlProvider";
            string        proof               = "c4ca4238a0b923820dcc509a6f75849b";
            string        questplugin         = "Saga.Map.Data.LuaQuest.dll, Saga.Map.Data.LuaQuest.LuaQuestProvider";
            string        scenarioquestplugin = "Saga.Map.Data.LuaQuest.dll, Saga.Map.Data.LuaQuest.ScenarioLuaQuest";
            string        worldspawn          = "Saga.Map.Plugins.dll, Saga.Map.Plugins.MultifileSpawnWorldObjects";
            string        multiworldspawn     = "Saga.Map.Plugins.dll, Saga.Map.Plugins.MultifileSpawnMultiWorldObjects";
            string        eventprovider       = "Saga.Map.Data.LuaQuest.dll, Saga.Map.Data.LuaQuest.EventInfo";
            ConsoleReader reader              = new ConsoleReader();

            reader.Clear(null);

            System.Configuration.Configuration b = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (CheckConfigExists() == false)
            {
                Console.WriteLine("First time run-configuration");
                char key;

                #region Always Configure

                ConfigureRequired("What is the world id of this server?");
                while (!byte.TryParse(Console.ReadLine(), out worldid))
                {
                    Console.WriteLine("Incorrect value please use an number between 0–255");
                }

                ConfigureRequired("What is the player limit of this server?");
                while (!int.TryParse(Console.ReadLine(), out playerlimit))
                {
                    Console.WriteLine("Incorrect value please use an valid number");
                }

                ConfigureRequired("What is the authentication proof of this server?");
                MD5           md5      = MD5.Create();
                byte[]        block    = Encoding.UTF8.GetBytes(Console.ReadLine());
                byte[]        md5block = md5.ComputeHash(block);
                StringBuilder builder  = new StringBuilder();
                foreach (byte c in md5block)
                {
                    builder.AppendFormat("{0:X2}", c);
                }
                proof = builder.ToString();

                ConfigureRequired("What are the cexp-rates?");
                while (!int.TryParse(Console.ReadLine(), out cexprates))
                {
                    Console.WriteLine("Incorrect value please use an between 1 and 20");
                }
                cexprates = Math.Min(20, Math.Max(cexprates, 1));

                ConfigureRequired("What are the jexp-rates?");
                while (!int.TryParse(Console.ReadLine(), out jexprates))
                {
                    Console.WriteLine("Incorrect value please use an between 1 and 20");
                }
                jexprates = Math.Min(20, Math.Max(jexprates, 1));

                ConfigureRequired("What are the wexp-rates?");
                while (!int.TryParse(Console.ReadLine(), out wexprates))
                {
                    Console.WriteLine("Incorrect value please use an between 1 and 20");
                }
                wexprates = Math.Min(20, Math.Max(wexprates, 1));

                ConfigureRequired("What are the item drop-rates?");
                while (!int.TryParse(Console.ReadLine(), out droprates))
                {
                    Console.WriteLine("Incorrect value please use an between 1 and 20");
                }
                droprates = Math.Min(20, Math.Max(droprates, 1));

                ConfigureRequired("Detect database plugin");
                dbprovider = FindPlugin(typeof(IDatabase), dbprovider);

                ConfigureRequired("Detect quest plugin");
                questplugin = FindPlugin(typeof(Saga.Quests.IQuest), questplugin);

                ConfigureRequired("Detect scenarion quest plugin");
                scenarioquestplugin = FindPlugin(typeof(Saga.Quests.ISceneraioQuest), scenarioquestplugin);

                ConfigureRequired("Detect npc & map spawn plugin");
                worldspawn = FindPlugin(typeof(Saga.Factory.SpawnWorldObjects), worldspawn);

                ConfigureRequired("Detect mob spawn plugin");
                multiworldspawn = FindPlugin(typeof(Saga.Factory.SpawnMultiWorldObjects), multiworldspawn);

                ConfigureRequired("Detect event plugin");
                eventprovider = FindPlugin(typeof(Saga.Factory.EventManager.BaseEventInfo), eventprovider);

                #endregion Always Configure

                #region Network Settings

ConfigureGatewayNetwork:
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Do you wan to configure the gateway-map network settings? Y/N");
                Console.ResetColor();
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What ip should the gateway-map server listen to?");
                    while (!IPAddress.TryParse(Console.ReadLine(), out gatewayip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("What port should the gateway-map server listen to?");
                    while (!int.TryParse(Console.ReadLine(), out gatewayport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64003");
                    }
                }
                else if (key != 'n')
                {
                    goto ConfigureGatewayNetwork;
                }

ConfigureWorldNetwork:
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Do you wan to configure the authentication-map network settings? Y/N");
                Console.ResetColor();
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What ip should the authentication-map server listen to?");
                    while (!IPAddress.TryParse(Console.ReadLine(), out mapip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("On what port is the authentication server listening");
                    while (!int.TryParse(Console.ReadLine(), out mapport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64002");
                    }
                }
                else if (key != 'n')
                {
                    goto ConfigureWorldNetwork;
                }

                #endregion Network Settings

                #region Database Settings

DatabaseName:
                ConfigureOptional("Do you want to configure the database settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    ConfigureRequired("What is the database name?");
                    databasename = Console.ReadLine();

                    ConfigureRequired("What is the database username?");
                    databaseusername = Console.ReadLine();

                    ConfigureRequired("What is the database password?");
                    databasepassword = Console.ReadLine();

                    ConfigureRequired("What is the database port?");
                    while (!uint.TryParse(Console.ReadLine(), out dbport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 3306");
                    }

                    ConfigureRequired("What is the database host?");
                    dbhost = Console.ReadLine();
                }
                else if (key != 'n')
                {
                    goto DatabaseName;
                }

                #endregion Database Settings



                #region Plugin detection

PluginDetection:
                ConfigureOptional("Do you want to dectect other plugins?");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("no plugins detected");
                }
                else if (key != 'n')
                {
                    goto PluginDetection;
                }

                #endregion Plugin detection

                //CONFIGURE SERVER SETTINGS
                ServerVars serverVarsConfiguration = new ServerVars();
                serverVarsConfiguration.DataDirectory = "../Data/";
                b.Sections.Add("Saga.ServerVars", serverVarsConfiguration);

                //CONFIGURE NETWORK SETTINGS
                NetworkSettings       networkSettings = new NetworkSettings();
                NetworkFileCollection collection      = networkSettings.Connections;
                collection["public"]   = new NetworkElement("public", gatewayip.ToString(), gatewayport);
                collection["internal"] = new NetworkElement("internal", mapip.ToString(), mapport);
                b.Sections.Remove("Saga.Manager.NetworkSettings");
                b.Sections.Add("Saga.Manager.NetworkSettings", networkSettings);
                networkSettings.WorldId     = worldid;
                networkSettings.Proof       = proof;
                networkSettings.PlayerLimit = playerlimit;

                //CONFIGURE CONSOLE SETTING
                ConsoleSettings consoleSettings = new ConsoleSettings();
                consoleSettings.CommandPrefix = "@";
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Broadcast"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Position"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.ChatMute"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.GmWarptomap"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.PlayerJump"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.PlayerCall"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Speed"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.GarbageCollector"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.ClearNpc"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.KickAll"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Kick"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Time"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.ShowMaintenance"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.ScheduleMaintenance"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.SetGmLevel"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Spawn"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Unspawn"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.GiveItem"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.QStart"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Kill"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Worldload"));
                consoleSettings.GmCommands.Add(new FactoryFileElement("Saga.Scripting.Console.Gmgo"));
                b.Sections.Add("Saga.Manager.ConsoleSettings", consoleSettings);

                //PORTALS
                PortalSettings portalSettings = new PortalSettings();
                portalSettings.FolderItems.Add(new FactoryFileElement("~/portal_data.csv", "text/csv"));
                b.Sections.Remove("Saga.Factory.Portals");
                b.Sections.Add("Saga.Factory.Portals", portalSettings);

                //CHARACTERCONFIGURATION
                CharacterConfigurationSettings characterconfigurationSettings = new CharacterConfigurationSettings();
                characterconfigurationSettings.FolderItems.Add(new FactoryFileElement("~/character-template.csv", "text/csv"));
                b.Sections.Remove("Saga.Factory.CharacterConfiguration");
                b.Sections.Add("Saga.Factory.CharacterConfiguration", characterconfigurationSettings);

                //ADDITION
                AdditionSettings additionSettings = new AdditionSettings();
                additionSettings.FolderItems.Add(new FactoryFileElement("~/Addition_t.xml", "text/xml"));
                additionSettings.Reference = "~/addition_reference.csv";
                b.Sections.Remove("Saga.Factory.Addition");
                b.Sections.Add("Saga.Factory.Addition", additionSettings);

                //SPELLS
                SpellSettings spellSettings = new SpellSettings();
                spellSettings.FolderItems.Add(new FactoryFileElement("~/spell_data.xml", "text/xml"));
                spellSettings.Reference = "~/skill_reference.csv";
                b.Sections.Remove("Saga.Factory.Spells");
                b.Sections.Add("Saga.Factory.Spells", spellSettings);

                //STATUSBYLEVEL
                StatusByLevelSettings statusbylevelSettings = new StatusByLevelSettings();
                statusbylevelSettings.FolderItems.Add(new FactoryFileElement("~/experience.csv", "text/csv"));
                statusbylevelSettings.Cexp     = cexprates;
                statusbylevelSettings.Jexp     = jexprates;
                statusbylevelSettings.Wexp     = wexprates;
                statusbylevelSettings.Droprate = droprates;

                b.Sections.Remove("Saga.Factory.StatusByLevel");
                b.Sections.Add("Saga.Factory.StatusByLevel", statusbylevelSettings);

                //WARPSETTINGS
                WarpSettings warpSettings = new WarpSettings();
                warpSettings.FolderItems.Add(new FactoryFileElement("~/warp_data.csv", "text/csv"));
                b.Sections.Remove("Saga.Factory.Warps");
                b.Sections.Add("Saga.Factory.Warps", warpSettings);

                //ZONES
                ZoneSettings zoneSettings = new ZoneSettings();
                zoneSettings.FolderItems.Add(new FactoryFileElement("~/zone_data.csv", "text/csv"));
                zoneSettings.Directory = "../Data/heightmaps";
                b.Sections.Remove("Saga.Factory.Zones");
                b.Sections.Add("Saga.Factory.Zones", zoneSettings);

                //ITEMS
                ItemSettings itemSettings = new ItemSettings();
                itemSettings.FolderItems.Add(new FactoryFileElement("~/item_data.xml", "text/xml"));
                b.Sections.Remove("Saga.Factory.Items");
                b.Sections.Add("Saga.Factory.Items", itemSettings);

                //WEAPONARY
                WeaponarySettings weaponarySettings = new WeaponarySettings();
                weaponarySettings.FolderItems.Add(new FactoryFileElement("~/weapon_data.csv", "text/csv"));
                b.Sections.Remove("Saga.Factory.Weaponary");
                b.Sections.Add("Saga.Factory.Weaponary", weaponarySettings);

                //SPAWNTEMPLATE
                SpawntemplateSettings spawntemplateSettings = new SpawntemplateSettings();
                spawntemplateSettings.FolderItems.Add(new FactoryFileElement("~/npc_templates.csv", "text/csv"));
                spawntemplateSettings.FolderItems.Add(new FactoryFileElement("~/item_templates.csv", "text/csv"));
                b.Sections.Remove("Saga.Factory.SpawnTemplate");
                b.Sections.Add("Saga.Factory.SpawnTemplate", spawntemplateSettings);

                //SPAWNS NPC & MAP
                SpawnWorldObjectSettings spawnworldobjectSettings = new SpawnWorldObjectSettings();
                spawnworldobjectSettings.FolderItems.Add(new FactoryFileElement("~/npc-spawns/", "text/csv"));
                spawnworldobjectSettings.FolderItems.Add(new FactoryFileElement("~/item-spawns/", "text/csv"));
                spawnworldobjectSettings.DerivedType = worldspawn;
                b.Sections.Remove("Saga.Factory.SpawnWorldObjects");
                b.Sections.Add("Saga.Factory.SpawnWorldObjects", spawnworldobjectSettings);

                //SPAWNS MOBS
                SpawnMultiWorldObjectSettings spawnmultiworldobjectSettings = new SpawnMultiWorldObjectSettings();
                spawnmultiworldobjectSettings.FolderItems.Add(new FactoryFileElement("~/mob-spawns/", "text/csv"));
                spawnmultiworldobjectSettings.DerivedType = multiworldspawn;
                b.Sections.Remove("Saga.Factory.SpawnMultiWorldObjects");
                b.Sections.Add("Saga.Factory.SpawnMultiWorldObjects", spawnmultiworldobjectSettings);

                //SCRIPTING
                ScriptingSettings scriptingSettings = new ScriptingSettings();
                scriptingSettings.Directory = "../Saga.Scripting";
                scriptingSettings.Assemblies.Add(new FactoryFileElement("System.dll", "text/csv"));
                scriptingSettings.Assemblies.Add(new FactoryFileElement("System.Data.dll", "text/csv"));
                scriptingSettings.Assemblies.Add(new FactoryFileElement("System.Xml.dll", "text/csv"));
                b.Sections.Remove("Saga.Manager.Scripting");
                b.Sections.Add("Saga.Manager.Scripting", scriptingSettings);

                //EVENTS
                EventSettings eventSettings = new EventSettings();
                eventSettings.FolderItems.Add(new FactoryFileElement("~/eventlist.csv", "text/csv"));
                eventSettings.Provider = eventprovider;
                b.Sections.Remove("Saga.Factory.Events");
                b.Sections.Add("Saga.Factory.Events", eventSettings);

                //QUUESTS
                QuestSettings questSettings = new QuestSettings();
                questSettings.Directory        = "../Quests/";
                questSettings.SDirectory       = "~/Scenario.Quests/";
                questSettings.Provider         = questplugin;
                questSettings.ScenarioProvider = scenarioquestplugin;
                b.Sections.Remove("Saga.Manager.Quest");
                b.Sections.Add("Saga.Manager.Quest", questSettings);

                //DATABASE SETTINGS
                DatabaseSettings databaseSettings = new DatabaseSettings();
                databaseSettings.Database = databasename;
                databaseSettings.Username = databaseusername;
                databaseSettings.Password = databasepassword;
                databaseSettings.Port     = dbport;
                databaseSettings.Host     = dbhost;
                databaseSettings.DBType   = dbprovider;
                b.Sections.Remove("Saga.Manager.Database");
                b.Sections.Add("Saga.Manager.Database", databaseSettings);

                //SAVE CONFIGURATION AND REFRESH ALL SECTIONS
                b.Save();

                //REFRESH ALL SECTIONS
                ConfigurationManager.RefreshSection("Saga.Factory.SpawnMultiWorldObjects");
                ConfigurationManager.RefreshSection("Saga.Manager.Database");
                ConfigurationManager.RefreshSection("Saga.Manager.Quest");
                ConfigurationManager.RefreshSection("Saga.Manager.Scripting");
                ConfigurationManager.RefreshSection("Saga.Factory.Events");
                ConfigurationManager.RefreshSection("Saga.Factory.SpawnWorldObject");
                ConfigurationManager.RefreshSection("Saga.ServerVars");
                ConfigurationManager.RefreshSection("Saga.Manager.NetworkSettings");
                ConfigurationManager.RefreshSection("Saga.Manager.ConsoleSettings");
                ConfigurationManager.RefreshSection("Saga.Factory.Portals");
                ConfigurationManager.RefreshSection("Saga.Factory.CharacterConfiguration");
                ConfigurationManager.RefreshSection("Saga.Factory.Addition");
                ConfigurationManager.RefreshSection("Saga.Factory.Spells");
                ConfigurationManager.RefreshSection("Saga.Factory.StatusByLevel");
                ConfigurationManager.RefreshSection("Saga.Factory.Warps");
                ConfigurationManager.RefreshSection("Saga.Factory.Zones");
                ConfigurationManager.RefreshSection("Saga.Factory.Items");
                ConfigurationManager.RefreshSection("Saga.Factory.Weaponary");
                ConfigurationManager.RefreshSection("Saga.Factory.SpawnTemplate");

                Console.WriteLine("Everything configured");
            }
        }