コード例 #1
0
ファイル: EditorShop.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorShop"/> class.
        /// </summary>
        /// <param name="id">The <see cref="ShopID"/>.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentException">No shop exists for the specified <paramref name="id"/>.</exception>
        public EditorShop(ShopID id, IDbController dbController)
        {
            _id = id;

            // Grab the general shop information
            var table = dbController.GetQuery <SelectShopQuery>().Execute(id);

            if (table == null)
            {
                const string errmsg = "No Shop with ID `{0}` exists.";
                throw new ArgumentException(string.Format(errmsg, id), "id");
            }

            Debug.Assert(id == table.ID);

            Name   = table.Name;
            CanBuy = table.CanBuy;

            // Grab the items from the database and add them
            var dbItems = dbController.GetQuery <SelectShopItemsQuery>().Execute(id);

            _items = new List <ItemTemplateID>();
            if (dbItems != null)
            {
                _items.AddRange(dbItems.Select(x => x.ItemTemplateID));
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BanningManagerBase{TAccountID}"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to use.</param>
        protected BanningManagerBase(IDbController dbController)
        {
            _dbController = dbController;

            _procIsBanned   = DbController.GetQuery <StoredProcIsBanned>();
            _procGetReasons = DbController.GetQuery <StoredProcGetReasons>();
        }
コード例 #3
0
ファイル: UserAccountManager.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="UserAccountManager"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        public UserAccountManager(IDbController dbController)
        {
            if (dbController == null)
                throw new ArgumentNullException("dbController");

            _dbController = dbController;
        }
コード例 #4
0
        /// <summary>
        /// Deletes the MapSpawnValues from the database. After this is called, this MapSpawnValues must be treated
        /// as disposed and not be used at all!
        /// </summary>
        public void Delete()
        {
            if (DbController == null)
            {
                const string errmsg = "Called Delete() on `{0}` when the DbController was already null. Likely already deleted.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, this);
                }
                Debug.Fail(string.Format(errmsg, this));
                return;
            }

            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Deleting MapSpawnValues `{0}`.", this);
            }

            var id = ID;

            DbController.GetQuery <DeleteMapSpawnQuery>().Execute(id);
            DbController.GetQuery <MapSpawnValuesIDCreator>().FreeID(id);

            _dbController = null;
        }
コード例 #5
0
        /// <summary>
        /// Loads a MapSpawnValues from the database.
        /// </summary>
        /// <param name="dbController">DbController used to communicate with the database.</param>
        /// <param name="id">ID of the MapSpawnValues to load.</param>
        /// <returns>The MapSpawnValues with ID <paramref name="id"/>.</returns>
        public static MapSpawnValues Load(IDbController dbController, MapSpawnValuesID id)
        {
            var values = dbController.GetQuery <SelectMapSpawnQuery>().Execute(id);

            Debug.Assert(id == values.ID);
            return(new MapSpawnValues(dbController, values));
        }
コード例 #6
0
ファイル: ShopManager.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// When overridden in the derived class, provides a chance to cache frequently used queries instead of
        /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely
        /// optional, but if you do cache any queries, it should be done here. Do not use this method for
        /// anything other than caching queries from the <paramref name="dbController"/>.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param>
        protected override void CacheDbQueries(IDbController dbController)
        {
            _selectShopItemsQuery = dbController.GetQuery <SelectShopItemsQuery>();
            _selectShopQuery      = dbController.GetQuery <SelectShopQuery>();

            base.CacheDbQueries(dbController);
        }
コード例 #7
0
        /// <summary>
        /// Attempts to create a <see cref="IDbController"/> from a <see cref="DbConnectionSettings"/>. If the
        /// <see cref="IDbController"/> failed to be created, a prompt will be presented to edit the values and retry.
        /// </summary>
        /// <param name="s">The <see cref="DbConnectionSettings"/>.</param>
        /// <param name="createController">The <see cref="Func{T,TResult}"/> describing how to create the
        /// <see cref="IDbController"/> instance.</param>
        /// <param name="createPrompt">The <see cref="Func{T,U}"/> to create the prompt asking to change the values.</param>
        /// <returns>
        /// The <see cref="IDbController"/> instance, or null if the user aborted before making
        /// a successful connection.
        /// </returns>
        public static IDbController CreateDbControllerPromptEditWhenInvalid(this DbConnectionSettings s,
                                                                            Func <DbConnectionSettings, IDbController> createController, Func <string, bool> createPrompt)
        {
            IDbController ret = null;

            while (true)
            {
                string msg = null;

                try
                {
                    ret = createController(s);
                }
                catch (DatabaseConnectionException ex)
                {
                    msg = ex.Message;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }

                if (ret != null)
                {
                    break;
                }

                if (!createPrompt(msg))
                {
                    return(null);
                }
            }

            return(ret);
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorCharacterTemplate"/> class.
        /// </summary>
        /// <param name="charTemplateTable">The <see cref="ICharacterTemplateTable"/>.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        public EditorCharacterTemplate(ICharacterTemplateTable charTemplateTable, IDbController dbController)
        {
            var id = charTemplateTable.ID;

            // Load the main table values
            CopyValuesFrom(charTemplateTable);

            // Load values from other tables
            // Equipped
            var equippedRaw = dbController.GetQuery<SelectCharacterTemplateEquippedQuery>().Execute(id);
            if (equippedRaw != null)
            {
                var equipped = equippedRaw.Select(x => new CharacterTemplateEquippedItem(x.ItemTemplateID, x.Chance));
                _equipped.AddRange(equipped);
            }

            // Inventory
            var inventoryRaw = dbController.GetQuery<SelectCharacterTemplateInventoryQuery>().Execute(id);
            if (inventoryRaw != null)
            {
                var inventory =
                    inventoryRaw.Select(x => new CharacterTemplateInventoryItem(x.ItemTemplateID, x.Chance, x.Min, x.Max));
                _inventory.AddRange(inventory);
            }

            // Known skills
            var knownSkills = dbController.GetQuery<SelectCharacterTemplateSkillsQuery>().Execute(id);
            if (knownSkills != null)
                _knownSkills.AddRange(knownSkills);

            // Quests
            var quests = dbController.GetQuery<SelectCharacterTemplateQuestsQuery>().Execute(id);
            if (quests != null)
                _quests.AddRange(quests);
        }
コード例 #9
0
ファイル: GlobalState.cs プロジェクト: mateuscezar/netgore
        /// <summary>
        /// Initializes a new instance of the <see cref="GlobalState"/> class.
        /// </summary>
        GlobalState()
        {
            ThreadAsserts.IsMainThread();

            // Load all sorts of stuff
            _contentManager = NetGore.Content.ContentManager.Create();

            var dbConnSettings = new DbConnectionSettings();
            _dbController =
                dbConnSettings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()),
                    x => dbConnSettings.PromptEditFileMessageBox(x));

            _defaultRenderFont = ContentManager.LoadFont("Font/Arial", 16, ContentLevel.Global);

            Character.NameFont = DefaultRenderFont;

            GrhInfo.Load(ContentPaths.Dev, ContentManager);
            AutomaticGrhDataSizeUpdater.Instance.UpdateSizes();

            _mapGrhWalls = new MapGrhWalls(ContentPaths.Dev, x => new WallEntity(x));

            // Load the child classes
            _mapState = new MapState(this);

            // Grab the audio manager instances, which will ensure that they are property initialized
            // before something that can't pass it an ContentManager tries to get an instance
            AudioManager.GetInstance(ContentManager);

            // Set the custom UITypeEditors
            CustomUITypeEditors.AddEditors(DbController);

            // Set up the timer
            _timer = new Timer { Interval = 1000 / 60 };
            _timer.Tick += _timer_Tick;
        }
コード例 #10
0
ファイル: Quest.cs プロジェクト: thepirateclub/netgore
        /// <summary>
        /// Loads the requirements for starting a quest.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to use to load values.</param>
        /// <returns>The requirements for starting a quest.</returns>
        IQuestRequirementCollection <User> LoadStartRequirements(IDbController dbController)
        {
            var questManager = QuestManager.Instance;
            var l            = new List <IQuestRequirement <User> >();

            // Items
            var reqItems = dbController.GetQuery <SelectQuestRequireStartItemQuery>().Execute(QuestID);

            if (!reqItems.IsEmpty())
            {
                l.Add(new ItemsQuestRequirement(this,
                                                reqItems.Select(x => new QuestItemTemplateAmount(x.ItemTemplateID, x.Amount))));
            }

            // Complete quests
            var reqCompleteQuests = dbController.GetQuery <SelectQuestRequireStartCompleteQuestsQuery>().Execute(QuestID);

            if (!reqCompleteQuests.IsEmpty())
            {
                if (!questManager.IsEmpty())
                {
                    l.Add(new CompleteQuestQuestRequirement(this, reqCompleteQuests.Select(questManager.GetQuest)));
                }
            }

            return(new QuestRequirementCollection <User>(l));
        }
コード例 #11
0
 /// <summary>
 /// Initializes the <see cref="PersistentCharacterStatusEffects"/> class.
 /// </summary>
 static PersistentCharacterStatusEffects()
 {
     _dbController = DbControllerBase.GetInstance();
     _insertQuery  = _dbController.GetQuery <InsertCharacterStatusEffectQuery>();
     _deleteQuery  = _dbController.GetQuery <DeleteCharacterStatusEffectQuery>();
     _updateQuery  = _dbController.GetQuery <UpdateCharacterStatusEffectQuery>();
 }
コード例 #12
0
 /// <summary>
 /// Initializes the <see cref="PersistentCharacterStatusEffects"/> class.
 /// </summary>
 static PersistentCharacterStatusEffects()
 {
     _dbController = DbControllerBase.GetInstance();
     _insertQuery = _dbController.GetQuery<InsertCharacterStatusEffectQuery>();
     _deleteQuery = _dbController.GetQuery<DeleteCharacterStatusEffectQuery>();
     _updateQuery = _dbController.GetQuery<UpdateCharacterStatusEffectQuery>();
 }
コード例 #13
0
ファイル: MapHelper.cs プロジェクト: thepirateclub/netgore
        /// <summary>
        /// Gets the <see cref="IMapTable"/>s for all of the maps.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to use. If null, will attempt to find
        /// the <see cref="IDbController"/> instance automatically.</param>
        /// <returns>
        /// The <see cref="IMapTable"/>s for all of the maps.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="dbController"/> is null and no valid <see cref="IDbController"/>
        /// instance could be found automatically.</exception>
        public static IEnumerable <IMapTable> FindAllMaps(IDbController dbController = null)
        {
            if (dbController == null)
            {
                dbController = DbControllerBase.GetInstance();
            }

            if (dbController == null)
            {
                throw new ArgumentException("Param was null and could not find a valid IDbController instance.", "dbController");
            }

            // Get the IDs
            var ids = dbController.GetQuery <SelectMapIDsQuery>().Execute();

            // Get all of the maps one at a time using the IDs
            var ret           = new List <IMapTable>();
            var templateQuery = dbController.GetQuery <SelectMapQuery>();

            foreach (var id in ids)
            {
                var template = templateQuery.Execute(id);
                ret.Add(template);
            }

            // Return the results sorted
            return(ret.OrderBy(x => x.ID).ToImmutable());
        }
コード例 #14
0
ファイル: AllianceManager.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// When overridden in the derived class, provides a chance to cache frequently used queries instead of
        /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely
        /// optional, but if you do cache any queries, it should be done here. Do not use this method for
        /// anything other than caching queries from the <paramref name="dbController"/>.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param>
        protected override void CacheDbQueries(IDbController dbController)
        {
            _selectAllianceQuery           = dbController.GetQuery <SelectAllianceQuery>();
            _selectAllianceAttackableQuery = dbController.GetQuery <SelectAllianceAttackableQuery>();
            _selectAllianceHostileQuery    = dbController.GetQuery <SelectAllianceHostileQuery>();

            base.CacheDbQueries(dbController);
        }
コード例 #15
0
        /// <summary>
        /// Gets and reserves the next free <see cref="ItemTemplateID"/>.
        /// </summary>
        /// <param name="dbController">The db controller.</param>
        /// <returns>The next free <see cref="ItemTemplateID"/>.</returns>
        public static ItemTemplateID ReserveFreeItemTemplateID(IDbController dbController)
        {
            var getUsedQuery    = dbController.GetQuery <SelectItemTemplateIDsQuery>();
            var selectQuery     = dbController.GetQuery <SelectItemTemplateQuery>();
            var insertByIDQuery = dbController.GetQuery <InsertItemTemplateIDOnlyQuery>();

            return(GetFreeID(dbController, true, t => new ItemTemplateID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute, insertByIDQuery.Execute));
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UserAccountManager"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        public UserAccountManager(IDbController dbController)
        {
            if (dbController == null)
            {
                throw new ArgumentNullException("dbController");
            }

            _dbController = dbController;
        }
コード例 #17
0
 /// <summary>
 /// Ensures that the given columns exist.
 /// </summary>
 /// <param name="db">The <see cref="IDbController"/>.</param>
 /// <param name="dbTable">The name of the table to check.</param>
 /// <param name="columns">The columns to check that exist in the given <paramref name="dbTable"/>.</param>
 static void EnsureColumnsExist(IDbController db, string dbTable, IEnumerable<string> columns)
 {
     var dbColumns = db.GetTableColumns(dbTable);
     foreach (var column in columns)
     {
         if (!dbColumns.Contains(column))
             Error("Table `{0}` does not contain required column `{1}`.", dbTable, column);
     }
 }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The DbController used to synchronize changes to the values.</param>
 /// <param name="id">The unique ID of this MapSpawnValues.</param>
 /// <param name="mapID">The index of the Map that these values are for.</param>
 /// <param name="characterTemplateID">The CharacterTemplateID of the CharacterTemplate to spawn.</param>
 /// <param name="spawnAmount">The maximum number of Characters that will be spawned by this MapSpawnValues.</param>
 /// <param name="spawnRect">The area on the map the spawning will take place at.</param>
 MapSpawnValues(IDbController dbController, MapSpawnValuesID id, MapID mapID, CharacterTemplateID characterTemplateID,
                byte spawnAmount, MapSpawnRect spawnRect)
 {
     _dbController        = dbController;
     _id                  = id;
     _mapID               = mapID;
     _characterTemplateID = characterTemplateID;
     _spawnAmount         = spawnAmount;
     _spawnArea           = spawnRect;
 }
コード例 #19
0
        /// <summary>
        /// When overridden in the derived class, provides a chance to cache frequently used queries instead of
        /// having to grab the query from the <see cref="IDbController"/> every time. Caching is completely
        /// optional, but if you do cache any queries, it should be done here. Do not use this method for
        /// anything other than caching queries from the <paramref name="dbController"/>.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to grab the queries from.</param>
        protected override void CacheDbQueries(IDbController dbController)
        {
            _selectCharacterTemplateQuery = dbController.GetQuery <SelectCharacterTemplateQuery>();
            _selectInventoryQuery         = dbController.GetQuery <SelectCharacterTemplateInventoryQuery>();
            _selectEquippedQuery          = dbController.GetQuery <SelectCharacterTemplateEquippedQuery>();
            _selectQuestsQuery            = dbController.GetQuery <SelectCharacterTemplateQuestsQuery>();
            _selectSkillsQuery            = dbController.GetQuery <SelectCharacterTemplateSkillsQuery>();

            base.CacheDbQueries(dbController);
        }
コード例 #20
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The DbController used to synchronize changes to the values.</param>
 /// <param name="id">The unique ID of this MapSpawnValues.</param>
 /// <param name="mapID">The index of the Map that these values are for.</param>
 /// <param name="characterTemplateID">The CharacterTemplateID of the CharacterTemplate to spawn.</param>
 /// <param name="spawnAmount">The maximum number of Characters that will be spawned by this MapSpawnValues.</param>
 /// <param name="spawnRect">The area on the map the spawning will take place at.</param>
 MapSpawnValues(IDbController dbController, MapSpawnValuesID id, MapID mapID, CharacterTemplateID characterTemplateID,
                byte spawnAmount, MapSpawnRect spawnRect)
 {
     _dbController = dbController;
     _id = id;
     _mapID = mapID;
     _characterTemplateID = characterTemplateID;
     _spawnAmount = spawnAmount;
     _spawnArea = spawnRect;
 }
コード例 #21
0
ファイル: GuildMemberPerformer.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="GuildMemberPerformerBase"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <param name="findGuildMember">The <see cref="Func{T,U}"/> used to find a guild member by name.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="findGuildMember" /> is <c>null</c>.</exception>
        public GuildMemberPerformer(IDbController dbController, Func<string, IGuildMember> findGuildMember)
            : base(GetSaveHandler(dbController))
        {
            if (dbController == null)
                throw new ArgumentNullException("dbController");
            if (findGuildMember == null)
                throw new ArgumentNullException("findGuildMember");

            _findGuildMember = findGuildMember;
            _selectGuildMemberQuery = dbController.GetQuery<SelectGuildMemberByNameQuery>();
        }
コード例 #22
0
        /// <summary>
        /// Gets and reserves the next free <see cref="ShopID"/>.
        /// </summary>
        /// <param name="dbController">The db controller.</param>
        /// <returns>The next free <see cref="ShopID"/>.</returns>
        public static ShopID ReserveFreeShopID(IDbController dbController)
        {
            var getUsedQuery    = dbController.GetQuery <SelectShopIDsQuery>();
            var selectQuery     = dbController.GetQuery <SelectShopQuery>();
            var insertByIDQuery = dbController.GetQuery <InsertUpdateShopQuery>();

            return(GetFreeID(dbController, true, t => new ShopID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute,
                             x => insertByIDQuery.Execute(new ShopTable {
                ID = x, Name = string.Empty
            })));
        }
コード例 #23
0
        /// <summary>
        /// Gets and reserves the next free <see cref="QuestID"/>.
        /// </summary>
        /// <param name="dbController">The db controller.</param>
        /// <returns>The next free <see cref="QuestID"/>.</returns>
        public static QuestID ReserveFreeQuestID(IDbController dbController)
        {
            var getUsedQuery    = dbController.GetQuery <SelectQuestIDsQuery>();
            var selectQuery     = dbController.GetQuery <SelectQuestQuery>();
            var insertByIDQuery = dbController.GetQuery <InsertQuestQuery>();

            return(GetFreeID(dbController, true, t => new QuestID(t), x => (int)x, getUsedQuery.Execute, selectQuery.Execute,
                             x => insertByIDQuery.Execute(new QuestTable {
                ID = x
            })));
        }
コード例 #24
0
        /// <summary>
        /// Ensures that the given columns exist.
        /// </summary>
        /// <param name="db">The <see cref="IDbController"/>.</param>
        /// <param name="dbTable">The name of the table to check.</param>
        /// <param name="columns">The columns to check that exist in the given <paramref name="dbTable"/>.</param>
        static void EnsureColumnsExist(IDbController db, string dbTable, IEnumerable <string> columns)
        {
            var dbColumns = db.GetTableColumns(dbTable);

            foreach (var column in columns)
            {
                if (!dbColumns.Contains(column))
                {
                    Error("Table `{0}` does not contain required column `{1}`.", dbTable, column);
                }
            }
        }
コード例 #25
0
ファイル: DbComponent.cs プロジェクト: walklook/Cubizer
        public override void OnDisable()
        {
            context.behaviour.events.OnLoadChunkAfter    -= this.OnLoadChunkDataAfter;
            context.behaviour.events.OnAddBlockBefore    -= this.OnAddBlockBefore;
            context.behaviour.events.OnRemoveBlockBefore -= this.OnRemoveBlockBefore;

            if (_dbControl != null)
            {
                _dbControl.Dispose();
                _dbControl = null;
            }
        }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The DbController used to synchronize changes to the values.</param>
 /// <param name="id">The unique ID of this MapSpawnValues.</param>
 /// <param name="mapID">The index of the Map that these values are for.</param>
 /// <param name="characterTemplateID">The CharacterTemplateID of the CharacterTemplate to spawn.</param>
 /// <param name="spawnAmount">The maximum number of Characters that will be spawned by this MapSpawnValues.</param>
 /// <param name="spawnRect">The area on the map the spawning will take place at.</param>
 /// <param name="spawnDirection">The direction on this map to spawn the NPCs.</param>
 /// <param name="spawnRespawn">The time it takes for an NPC to spawn.</param>
 MapSpawnValues(IDbController dbController, MapSpawnValuesID id, MapID mapID, CharacterTemplateID characterTemplateID,
                byte spawnAmount, MapSpawnRect spawnRect, Direction spawnDirection, ushort spawnRespawn)
 {
     _dbController        = dbController;
     _id                  = id;
     _mapID               = mapID;
     _characterTemplateID = characterTemplateID;
     _spawnAmount         = spawnAmount;
     _spawnArea           = spawnRect;
     _spawnDirection      = spawnDirection;
     _spawnRespawn        = spawnRespawn;
 }
コード例 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Quest"/> class.
        /// </summary>
        /// <param name="questID">The quest's ID.</param>
        /// <param name="dbController">The <see cref="IDbController"/> to use to load the values.</param>
        public Quest(QuestID questID, IDbController dbController)
        {
            _questID = questID;

            var info = dbController.GetQuery <SelectQuestQuery>().Execute(questID);

            _repeatable = info.Repeatable;

            _rewards            = LoadRewards(questID, info, dbController);
            _startRequirements  = LoadStartRequirements(dbController);
            _finishRequirements = LoadFinishRequirements(dbController);
        }
コード例 #28
0
ファイル: MapSpawnValues.cs プロジェクト: Furt/netgore
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The DbController used to synchronize changes to the values.</param>
 /// <param name="id">The unique ID of this MapSpawnValues.</param>
 /// <param name="mapID">The index of the Map that these values are for.</param>
 /// <param name="characterTemplateID">The CharacterTemplateID of the CharacterTemplate to spawn.</param>
 /// <param name="spawnAmount">The maximum number of Characters that will be spawned by this MapSpawnValues.</param>
 /// <param name="spawnRect">The area on the map the spawning will take place at.</param>
 /// <param name="spawnDirection">The direction on this map to spawn the NPCs.</param>
 /// <param name="spawnRespawn">The time it takes for an NPC to spawn.</param>
 MapSpawnValues(IDbController dbController, MapSpawnValuesID id, MapID mapID, CharacterTemplateID characterTemplateID,
                byte spawnAmount, MapSpawnRect spawnRect, Direction spawnDirection, ushort spawnRespawn)
 {
     _dbController = dbController;
     _id = id;
     _mapID = mapID;
     _characterTemplateID = characterTemplateID;
     _spawnAmount = spawnAmount;
     _spawnArea = spawnRect;
     _spawnDirection = spawnDirection;
     _spawnRespawn = spawnRespawn;
 }
コード例 #29
0
ファイル: GuildManager.cs プロジェクト: thepirateclub/netgore
        /// <summary>
        /// Initializes a new instance of the <see cref="GuildManagerBase{T}"/> class.
        /// </summary>
        GuildManager(IDbController dbController)
        {
            _dbController = dbController;

            // Cache the queries this object will be using
            _selectGuildByNameQuery = _dbController.GetQuery <SelectGuildByNameQuery>();
            _selectGuildByTagQuery  = _dbController.GetQuery <SelectGuildByTagQuery>();
            _insertGuildEventQuery  = _dbController.GetQuery <InsertGuildEventQuery>();
            _insertGuildQuery       = _dbController.GetQuery <InsertGuildQuery>();

            Initialize();
        }
コード例 #30
0
ファイル: EditorQuest.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorQuest"/> class.
        /// </summary>
        /// <param name="questID">The quest ID.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentException">No quests for the given <paramref name="questID"/> exist.</exception>
        public EditorQuest(QuestID questID, IDbController dbController)
        {
            _id = questID;

            // Get the quest database table row
            var questTable = dbController.GetQuery <SelectQuestQuery>().Execute(questID);

            if (questTable == null)
            {
                const string errmsg = "Invalid QuestID ({0}) supplied - no quests with this ID exists.";
                throw new ArgumentException(string.Format(errmsg, questID), "questID");
            }

            Debug.Assert(questID == questTable.ID);

            // Get the quest description stuff from the client-side
            var qd = _questDescriptions[ID];

            if (qd != null)
            {
                Name        = qd.Name;
                Description = qd.Description;
            }
            else
            {
                Name        = string.Empty;
                Description = string.Empty;
            }

            // Get the quest details from the server side
            RewardExp  = questTable.RewardExp;
            RewardCash = questTable.RewardCash;
            Repeatable = questTable.Repeatable;

            _startItems =
                dbController.GetQuery <SelectQuestRequireStartItemQuery>().Execute(questID).Select(
                    x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();
            _finishItems =
                dbController.GetQuery <SelectQuestRequireFinishItemQuery>().Execute(questID).Select(
                    x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();

            _startQuests  = dbController.GetQuery <SelectQuestRequireStartCompleteQuestsQuery>().Execute(questID).ToList();
            _finishQuests = dbController.GetQuery <SelectQuestRequireFinishCompleteQuestsQuery>().Execute(questID).ToList();

            _rewardItems =
                dbController.GetQuery <SelectQuestRewardItemQuery>().Execute(questID).Select(
                    x => new MutablePair <ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();

            _kills =
                dbController.GetQuery <SelectQuestRequireKillQuery>().Execute(questID).Select(
                    x => new MutablePair <CharacterTemplateID, ushort>(x.CharacterTemplateID, x.Amount)).ToList();
        }
コード例 #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbTableDataManager{TID, TItem}"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        protected DbTableDataManager(IDbController dbController)
        {
            if (dbController == null)
            {
                throw new ArgumentNullException("dbController");
            }

            _dbController = dbController;

            CacheDbQueries(_dbController);

            LoadAll();
        }
コード例 #32
0
        /// <summary>
        /// Loads all of the MapSpawnValues for the given <paramref name="mapID"/> from the database.
        /// </summary>
        /// <param name="dbController">DbController used to communicate with the database.</param>
        /// <param name="mapID">Index of the map to load the MapSpawnValues for.</param>
        /// <returns>An IEnumerable of all of the MapSpawnValues for the given <paramref name="mapID"/>.</returns>
        public static IEnumerable <MapSpawnValues> Load(IDbController dbController, MapID mapID)
        {
            var ret         = new List <MapSpawnValues>();
            var queryValues = dbController.GetQuery <SelectMapSpawnsOnMapQuery>().Execute(mapID);

            foreach (var v in queryValues)
            {
                Debug.Assert(v.MapID == mapID);
                ret.Add(new MapSpawnValues(dbController, v));
            }

            return(ret);
        }
コード例 #33
0
ファイル: EditorQuest.cs プロジェクト: mateuscezar/netgore
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorQuest"/> class.
        /// </summary>
        /// <param name="questID">The quest ID.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentException">No quests for the given <paramref name="questID"/> exist.</exception>
        public EditorQuest(QuestID questID, IDbController dbController)
        {
            _id = questID;

            // Get the quest database table row
            var questTable = dbController.GetQuery<SelectQuestQuery>().Execute(questID);
            if (questTable == null)
            {
                const string errmsg = "Invalid QuestID ({0}) supplied - no quests with this ID exists.";
                throw new ArgumentException(string.Format(errmsg, questID), "questID");
            }

            Debug.Assert(questID == questTable.ID);

            // Get the quest description stuff from the client-side
            var qd = _questDescriptions[ID];
            if (qd != null)
            {
                Name = qd.Name;
                Description = qd.Description;
            }
            else
            {
                Name = string.Empty;
                Description = string.Empty;
            }

            // Get the quest details from the server side
            RewardExp = questTable.RewardExp;
            RewardCash = questTable.RewardCash;
            Repeatable = questTable.Repeatable;

            _startItems =
                dbController.GetQuery<SelectQuestRequireStartItemQuery>().Execute(questID).Select(
                    x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();
            _finishItems =
                dbController.GetQuery<SelectQuestRequireFinishItemQuery>().Execute(questID).Select(
                    x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();

            _startQuests = dbController.GetQuery<SelectQuestRequireStartCompleteQuestsQuery>().Execute(questID).ToList();
            _finishQuests = dbController.GetQuery<SelectQuestRequireFinishCompleteQuestsQuery>().Execute(questID).ToList();

            _rewardItems =
                dbController.GetQuery<SelectQuestRewardItemQuery>().Execute(questID).Select(
                    x => new MutablePair<ItemTemplateID, byte>(x.ItemTemplateID, x.Amount)).ToList();

            _kills =
                dbController.GetQuery<SelectQuestRequireKillQuery>().Execute(questID).Select(
                    x => new MutablePair<CharacterTemplateID, ushort>(x.CharacterTemplateID, x.Amount)).ToList();
        }
コード例 #34
0
        /// <summary>
        /// Gets the next free <see cref="ItemTemplateID"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TTemplate">The type of the template.</typeparam>
        /// <param name="dbController">The db controller.</param>
        /// <param name="reserve">If true, the index will be reserved by inserting the default
        /// values for the column at the given index.</param>
        /// <param name="intToT">The int to T.</param>
        /// <param name="tToInt">The t to int.</param>
        /// <param name="getUsed">The get used.</param>
        /// <param name="selector">The selector.</param>
        /// <param name="inserter">The inserter.</param>
        /// <returns>
        /// The next free <see cref="ItemTemplateID"/>.
        /// </returns>
        public static T GetFreeID <T, TTemplate>(IDbController dbController, bool reserve, Func <int, T> intToT, Func <T, int> tToInt,
                                                 Func <IEnumerable <T> > getUsed, Func <T, TTemplate> selector, Action <T> inserter)
            where TTemplate : class
        {
            // Get the used IDs as ints
            var usedIDs = getUsed().Select(tToInt).ToImmutable();

            // Start with ID 0
            var idBase = 0;
            T   freeIDAsT;

            // Loop until we successfully find an ID that has no template
            var success = false;

            do
            {
                // Get the next free value
                var freeID = usedIDs.NextFreeValue(idBase);
                freeIDAsT = intToT(freeID);

                // Increase the base so that way, if it fails, we are forced to check a higher value
                idBase = freeID + 1;

                // Ensure the ID is free
                if (selector(freeIDAsT) != null)
                {
                    continue;
                }

                // Reserve the ID if needed
                if (reserve)
                {
                    try
                    {
                        inserter(freeIDAsT);
                    }
                    catch (DuplicateKeyException)
                    {
                        // Someone just grabbed the key - those jerks!
                        continue;
                    }
                }

                success = true;
            }while (!success);

            // Return the value
            return(freeIDAsT);
        }
コード例 #35
0
ファイル: GuildMemberPerformer.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="GuildMemberPerformerBase"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <param name="findGuildMember">The <see cref="Func{T,U}"/> used to find a guild member by name.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="findGuildMember" /> is <c>null</c>.</exception>
        public GuildMemberPerformer(IDbController dbController, Func <string, IGuildMember> findGuildMember)
            : base(GetSaveHandler(dbController))
        {
            if (dbController == null)
            {
                throw new ArgumentNullException("dbController");
            }
            if (findGuildMember == null)
            {
                throw new ArgumentNullException("findGuildMember");
            }

            _findGuildMember        = findGuildMember;
            _selectGuildMemberQuery = dbController.GetQuery <SelectGuildMemberByNameQuery>();
        }
コード例 #36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbTableDataManager{TID, TItem}"/> class.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="dbController" /> is <c>null</c>.</exception>
        protected DbTableDataManager(IDbController dbController)
        {
            if (dbController == null)
            {
                throw new ArgumentNullException("dbController");
            }

            _dbController = dbController;

            CacheDbQueries(_dbController);

            foreach (var id in GetIDs())
            {
                _items.Add(id, null);
            }
        }
コード例 #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorCharacterTemplate"/> class.
        /// </summary>
        /// <param name="charTemplateTable">The <see cref="ICharacterTemplateTable"/>.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        public EditorCharacterTemplate(ICharacterTemplateTable charTemplateTable, IDbController dbController)
        {
            var id = charTemplateTable.ID;

            // Load the main table values
            CopyValuesFrom(charTemplateTable);

            // Load values from other tables
            // Equipped
            var equippedRaw = dbController.GetQuery <SelectCharacterTemplateEquippedQuery>().Execute(id);

            if (equippedRaw != null)
            {
                var equipped = equippedRaw.Select(x => new CharacterTemplateEquippedItem(x.ItemTemplateID, x.Chance));
                _equipped.AddRange(equipped);
            }

            // Inventory
            var inventoryRaw = dbController.GetQuery <SelectCharacterTemplateInventoryQuery>().Execute(id);

            if (inventoryRaw != null)
            {
                var inventory =
                    inventoryRaw.Select(x => new CharacterTemplateInventoryItem(x.ItemTemplateID, x.Chance, x.Min, x.Max));
                _inventory.AddRange(inventory);
            }

            // Known skills
            var knownSkills = dbController.GetQuery <SelectCharacterTemplateSkillsQuery>().Execute(id);

            if (knownSkills != null)
            {
                _knownSkills.AddRange(knownSkills);
            }

            // Quests
            var quests = dbController.GetQuery <SelectCharacterTemplateQuestsQuery>().Execute(id);

            if (quests != null)
            {
                _quests.AddRange(quests);
            }
        }
コード例 #38
0
        /// <summary>
        /// Checks if the CharacterTemplate with the given CharacterTemplateID exists in the database.
        /// </summary>
        /// <param name="id">CharacterTemplateID to check.</param>
        /// <returns>True if a CharacterTemplate with the given id exists; otherwise false.</returns>
        public static bool TemplateExists(this CharacterTemplateID id)
        {
            IDbController dbController = DbControllerBase.GetInstance();
            var           query        = dbController.GetQuery <SelectCharacterTemplateQuery>();

            try
            {
                var result = query.Execute(id);
                if (result == null)
                {
                    return(false);
                }
            }
            catch (ArgumentException)
            {
                return(false);
            }

            return(true);
        }
コード例 #39
0
ファイル: DbComponent.cs プロジェクト: walklook/Cubizer
        public override void OnEnable()
        {
            _dbUrl = model.settings.url;
            if (string.IsNullOrEmpty(_dbUrl) || _dbUrl == "localhost")
            {
                _dbUrl = Application.persistentDataPath + "/";
            }

            _dbName = model.settings.name;
            if (string.IsNullOrEmpty(_dbName))
            {
                _dbName = "cubizer.db";
            }

            context.behaviour.events.OnLoadChunkAfter    += this.OnLoadChunkDataAfter;
            context.behaviour.events.OnAddBlockBefore    += this.OnAddBlockBefore;
            context.behaviour.events.OnRemoveBlockBefore += this.OnRemoveBlockBefore;

            _dbControl = new DbSqlite(_dbUrl + _dbName);
        }
コード例 #40
0
ファイル: EditorAlliance.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorAlliance"/> class.
        /// </summary>
        /// <param name="id">The <see cref="AllianceID"/>.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentException">No <see cref="Alliance"/> exists for the given <paramref name="id"/>.</exception>
        public EditorAlliance(AllianceID id, IDbController dbController)
        {
            _id = id;

            var table = dbController.GetQuery<SelectAllianceQuery>().Execute(id);
            if (table == null)
            {
                const string errmsg = "No Alliance with ID `{0}` exists.";
                throw new ArgumentException(string.Format(errmsg, id), "id");
            }

            Debug.Assert(id == table.ID);

            Name = table.Name;

            var attackable = dbController.GetQuery<SelectAllianceAttackableQuery>().Execute(id);
            _attackable = new List<AllianceID>(attackable.Select(x => x.AttackableID));

            var hostile = dbController.GetQuery<SelectAllianceHostileQuery>().Execute(id);
            _hostile = new List<AllianceID>(hostile.Select(x => x.HostileID));
        }
コード例 #41
0
ファイル: GuildMemberPerformer.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Creates an <see cref="Action{T}"/> needed for the <see cref="GuildMemberPerformer"/> to save the guild
        /// state of a <see cref="IGuildMember"/>.
        /// </summary>
        /// <param name="dbController"></param>
        /// <returns></returns>
        static Action<IGuildMember> GetSaveHandler(IDbController dbController)
        {
            var replaceQuery = dbController.GetQuery<InsertGuildMemberQuery>();
            var deleteQuery = dbController.GetQuery<DeleteGuildMemberQuery>();

            return delegate(IGuildMember target)
            {
                if (target.Guild == null)
                {
                    var id = new CharacterID(target.ID);
                    deleteQuery.Execute(id);
                }
                else
                {
                    var id = new CharacterID(target.ID);
                    var guildID = target.Guild.ID;
                    var rank = target.GuildRank;
                    var args = new InsertGuildMemberQuery.QueryArgs(id, guildID, rank);
                    replaceQuery.Execute(args);
                }
            };
        }
コード例 #42
0
ファイル: EditorShop.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorShop"/> class.
        /// </summary>
        /// <param name="id">The <see cref="ShopID"/>.</param>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        /// <exception cref="ArgumentException">No shop exists for the specified <paramref name="id"/>.</exception>
        public EditorShop(ShopID id, IDbController dbController)
        {
            _id = id;

            // Grab the general shop information
            var table = dbController.GetQuery<SelectShopQuery>().Execute(id);
            if (table == null)
            {
                const string errmsg = "No Shop with ID `{0}` exists.";
                throw new ArgumentException(string.Format(errmsg, id), "id");
            }

            Debug.Assert(id == table.ID);

            Name = table.Name;
            CanBuy = table.CanBuy;

            // Grab the items from the database and add them
            var dbItems = dbController.GetQuery<SelectShopItemsQuery>().Execute(id);
            _items = new List<ItemTemplateID>();
            if (dbItems != null)
                _items.AddRange(dbItems.Select(x => x.ItemTemplateID));
        }
コード例 #43
0
 /// <summary>
 /// Performs validation checks on the database tables to ensure the schemas are correct.
 /// </summary>
 /// <param name="db">The DbController to use for performing the validation checks.</param>
 public static void ValidateTables(IDbController db)
 {
     ValidateCharacterTable(db);
     ValidateCharacterTemplateTable(db);
 }
コード例 #44
0
 /// <summary>
 /// Performs validation checks on the CharacterTemplate table.
 /// </summary>
 /// <param name="db">The DbController to use for performing the validation checks.</param>
 static void ValidateCharacterTemplateTable(IDbController db)
 {
     EnsureStatColumnsExist(db, CharacterTemplateTable.TableName, EnumHelper<StatType>.Values, StatCollectionType.Base);
 }
コード例 #45
0
 /// <summary>
 /// Ensures that the columns needed for <see cref="StatType"/>s exist in a table.
 /// </summary>
 /// <param name="db">The <see cref="IDbController"/>.</param>
 /// <param name="dbTable">The name of the table to check.</param>
 /// <param name="columns">The <see cref="StatType"/>s to ensure exist.</param>
 /// <param name="statCollectionType">The <see cref="StatCollectionType"/> to use for checking.</param>
 static void EnsureStatColumnsExist(IDbController db, string dbTable, IEnumerable<StatType> columns,
                                    StatCollectionType statCollectionType)
 {
     EnsureColumnsExist(db, dbTable, columns.Select(x => x.GetDatabaseField(statCollectionType)));
 }
コード例 #46
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
 static MapSpawnValuesID GetFreeID(IDbController dbController)
 {
     return dbController.GetQuery<MapSpawnValuesIDCreator>().GetNext();
 }
コード例 #47
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Loads a MapSpawnValues from the database.
 /// </summary>
 /// <param name="dbController">DbController used to communicate with the database.</param>
 /// <param name="id">ID of the MapSpawnValues to load.</param>
 /// <returns>The MapSpawnValues with ID <paramref name="id"/>.</returns>
 public static MapSpawnValues Load(IDbController dbController, MapSpawnValuesID id)
 {
     var values = dbController.GetQuery<SelectMapSpawnQuery>().Execute(id);
     Debug.Assert(id == values.ID);
     return new MapSpawnValues(dbController, values);
 }
コード例 #48
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The IDbController used to synchronize changes to the values.</param>
 /// <param name="mapID">The index of the Map that these values are for.</param>
 /// <param name="characterTemplateID">The CharacterTemplateID of the CharacterTemplate to spawn.</param>
 public MapSpawnValues(IDbController dbController, MapID mapID, CharacterTemplateID characterTemplateID)
     : this(dbController, GetFreeID(dbController), mapID, characterTemplateID, 1, new MapSpawnRect(null, null, null, null))
 {
     DbController.GetQuery<InsertMapSpawnQuery>().Execute(this);
 }
コード例 #49
0
ファイル: Server.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            var settings = new DbConnectionSettings();
            _dbController =
                settings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()),
                    x => PromptEditDbSettingsFile(settings, x));

            if (_dbController == null)
                return;

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker { LogFilePath = ContentPaths.Build.Root.Join("querystats.txt") };
            queryStats.LogFileFrequency = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);
            cleaner.Run();

            // Load the game data and such
            InitializeScripts();

            // Create some objects
            _consoleCommands = new ConsoleCommands(this);
            _groupManager = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg);
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();
            ssv.Check(this);

            if (log.IsInfoEnabled)
                log.Info("Server loaded.");
        }
コード例 #50
0
ファイル: Server.cs プロジェクト: Furt/netgore
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            ThreadAsserts.IsMainThread();

            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Check if patching is needed
            int numMissingPatches = -1;
            try
            {
                numMissingPatches = ServerDbPatcher.GetMissingPatches().Length;
            }
            catch (Exception ex)
            {
                log.WarnFormat("Failed to find DbPatches directory, so could not check if patching is required. Exception: {0}", ex);
            }

            if (numMissingPatches > 0)
            {
                log.ErrorFormat("There are `{0}` NetGore db patches not applied. Please backup your database then run /DemoGame.Server/DbPatches/Patch.bat.", numMissingPatches);
                log.ErrorFormat("Server will auto-close after 10 seconds, and will keep doing this until you patch.");
                Thread.Sleep(10 * 1000);
                return;
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            _dbController = CreateDbController();

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker { LogFilePath = ContentPaths.Build.Root.Join("querystats.txt") };
            queryStats.LogFileFrequency = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);
            cleaner.Run();

            // Create some objects
            _consoleCommands = new ConsoleCommands(this);
            _groupManager = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg);
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();
            ssv.Check(this);

            if (log.IsInfoEnabled)
                log.Info("Server loaded.");
        }
コード例 #51
0
ファイル: MapHelper.cs プロジェクト: Vizzini/netgore
        /// <summary>
        /// Gets the <see cref="IMapTable"/>s for all of the maps.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/> to use. If null, will attempt to find
        /// the <see cref="IDbController"/> instance automatically.</param>
        /// <returns>
        /// The <see cref="IMapTable"/>s for all of the maps.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="dbController"/> is null and no valid <see cref="IDbController"/>
        /// instance could be found automatically.</exception>
        public static IEnumerable<IMapTable> FindAllMaps(IDbController dbController = null)
        {
            if (dbController == null)
                dbController = DbControllerBase.GetInstance();

            if (dbController == null)
                throw new ArgumentException("Param was null and could not find a valid IDbController instance.", "dbController");

            // Get the IDs
            var ids = dbController.GetQuery<SelectMapIDsQuery>().Execute();

            // Get all of the maps one at a time using the IDs
            var ret = new List<IMapTable>();
            var templateQuery = dbController.GetQuery<SelectMapQuery>();
            foreach (var id in ids)
            {
                var template = templateQuery.Execute(id);
                ret.Add(template);
            }

            // Return the results sorted
            return ret.OrderBy(x => x.ID).ToImmutable();
        }
コード例 #52
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Initializes a new instance of the <see cref="MapSpawnValues"/> class.
 /// </summary>
 /// <param name="dbController">The IDbController used to synchronize changes to the values.</param>
 /// <param name="v">The IMapSpawnTable containing the values to use.</param>
 MapSpawnValues(IDbController dbController, IMapSpawnTable v)
     : this(dbController, v.ID, v.MapID, v.CharacterTemplateID, v.Amount, new MapSpawnRect(v))
 {
 }
コード例 #53
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Deletes the MapSpawnValues from the database. After this is called, this MapSpawnValues must be treated
        /// as disposed and not be used at all!
        /// </summary>
        public void Delete()
        {
            if (DbController == null)
            {
                const string errmsg = "Called Delete() on `{0}` when the DbController was already null. Likely already deleted.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, this);
                Debug.Fail(string.Format(errmsg, this));
                return;
            }

            if (log.IsInfoEnabled)
                log.InfoFormat("Deleting MapSpawnValues `{0}`.", this);

            var id = ID;
            DbController.GetQuery<DeleteMapSpawnQuery>().Execute(id);
            DbController.GetQuery<MapSpawnValuesIDCreator>().FreeID(id);

            _dbController = null;
        }
コード例 #54
0
        /// <summary>
        /// Adds all of the custom <see cref="UITypeEditor"/>s.
        /// </summary>
        /// <param name="dbController">The <see cref="IDbController"/>.</param>
        public static void AddEditors(IDbController dbController)
        {
            // Set the db controller only if we weren't given a null one
            if (dbController != null)
                _dbController = dbController;

            // If we already added the custom editors, don't add them again
            if (_added)
                return;

            _added = true;

            // Add all of our custom UITypeEditors. Note that for value types, we have to make a call for both the
            // regular type and nullable type if we want to support nullable types. It is important that the
            // UITypeEditor, too, also supports the nullable type.
            NetGore.Editor.UI.CustomUITypeEditors.AddEditorsHelper(
                new EditorTypes(typeof(ActionDisplayID), typeof(ActionDisplayIDEditor)),
                new EditorTypes(typeof(ActionDisplayID?), typeof(ActionDisplayIDEditor)),
                new EditorTypes(typeof(CharacterTemplateID), typeof(CharacterTemplateIDEditor)),
                new EditorTypes(typeof(CharacterTemplateID?), typeof(CharacterTemplateIDEditor)),
                new EditorTypes(typeof(ItemTemplateID), typeof(ItemTemplateIDEditor)),
                new EditorTypes(typeof(ItemTemplateID?), typeof(ItemTemplateIDEditor)),
                new EditorTypes(typeof(AllianceID), typeof(AllianceIDEditor)),
                new EditorTypes(typeof(AllianceID?), typeof(AllianceIDEditor)),
                new EditorTypes(typeof(BodyID), typeof(BodyIDEditor)), new EditorTypes(typeof(BodyID?), typeof(BodyIDEditor)),
                new EditorTypes(typeof(BodyInfo), typeof(BodyInfo)), new EditorTypes(typeof(MapID), typeof(MapIDEditor)),
                new EditorTypes(typeof(MapID?), typeof(MapIDEditor)), new EditorTypes(typeof(ShopID), typeof(ShopIDEditor)),
                new EditorTypes(typeof(ShopID?), typeof(ShopIDEditor)),
                new EditorTypes(typeof(IEnumerable<KeyValuePair<StatType, int>>), typeof(StatTypeConstDictionaryEditor)),
                new EditorTypes(typeof(List<MutablePair<ItemTemplateID, byte>>), typeof(ItemTemplateAndAmountEditor)),
                new EditorTypes(typeof(List<QuestID>), typeof(QuestIDListEditor)),
                new EditorTypes(typeof(List<SkillType>), typeof(SkillTypeListEditor)),
                new EditorTypes(typeof(List<AllianceID>), typeof(AllianceIDListEditor)),
                new EditorTypes(typeof(List<ItemTemplateID>), typeof(ItemTemplateIDListEditor)),
                new EditorTypes(typeof(List<MutablePair<CharacterTemplateID, ushort>>), typeof(CharacterTemplateAndAmountEditor)),
                new EditorTypes(typeof(List<CharacterTemplateEquippedItem>), typeof(CharacterTemplateEquippedItemEditor)),
                new EditorTypes(typeof(List<CharacterTemplateInventoryItem>), typeof(CharacterTemplateInventoryItemEditor)),
                new EditorTypes(typeof(StatTypeConstDictionary), typeof(StatTypeConstDictionaryEditor)));

            // Add a TypeConverter for the type:
            //      IEnumerable<KeyValuePair<StatType, int>>
            // We just assume that this type will be for a StatTypeConstDictionary. This is what lets us actually
            // display the stats text. The editing of the valeus is done in the chunk above with the AddEditorsHelper().
            TypeDescriptor.AddAttributes(typeof(IEnumerable<KeyValuePair<StatType, int>>),
                new TypeConverterAttribute(typeof(StatTypeConstDictionaryTypeConverter)));

            // Add some other custom TypeConverters
            TypeDescriptor.AddAttributes(typeof(IEnumerable<MutablePair<CharacterTemplateID, ushort>>),
                new TypeConverterAttribute(typeof(CharacterTemplateAndAmountListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<MutablePair<ItemTemplateID, byte>>),
                new TypeConverterAttribute(typeof(ItemTemplateAndAmountListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<ItemTemplateID>),
                new TypeConverterAttribute(typeof(ItemTemplateListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<CharacterTemplateEquippedItem>),
                new TypeConverterAttribute(typeof(CharacterTemplateEquippedItemListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<CharacterTemplateInventoryItem>),
                new TypeConverterAttribute(typeof(CharacterTemplateInventoryItemListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<QuestID>),
                new TypeConverterAttribute(typeof(QuestIDListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<SkillType>),
                new TypeConverterAttribute(typeof(SkillTypeListTypeConverter)));

            TypeDescriptor.AddAttributes(typeof(IEnumerable<AllianceID>),
                new TypeConverterAttribute(typeof(AllianceIDListTypeConverter)));

            // Add the custom UITypeEditors defined by the base engine
            NetGore.Editor.UI.CustomUITypeEditors.AddEditors();
            NetGore.Editor.UI.CustomUITypeEditors.AddNPCChatDialogEditor(EditorNPCChatManager.Instance);
            NetGore.Editor.UI.CustomUITypeEditors.AddAIIDEditor(AIFactory.Instance);

            AddAdvancedClassTypeConverters();
            AddExtraTextProviders();
        }
コード例 #55
0
ファイル: MapSpawnValues.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Loads all of the MapSpawnValues for the given <paramref name="mapID"/> from the database.
        /// </summary>
        /// <param name="dbController">DbController used to communicate with the database.</param>
        /// <param name="mapID">Index of the map to load the MapSpawnValues for.</param>
        /// <returns>An IEnumerable of all of the MapSpawnValues for the given <paramref name="mapID"/>.</returns>
        public static IEnumerable<MapSpawnValues> Load(IDbController dbController, MapID mapID)
        {
            var ret = new List<MapSpawnValues>();
            var queryValues = dbController.GetQuery<SelectMapSpawnsOnMapQuery>().Execute(mapID);

            foreach (var v in queryValues)
            {
                Debug.Assert(v.MapID == mapID);
                ret.Add(new MapSpawnValues(dbController, v));
            }

            return ret;
        }