Ejemplo n.º 1
0
        public static void Initialize(bool autoRetry = true)
        {
            Authentication.Exists(true);
            World.Exists(true);

            var shardDb = new ShardDatabase();

            serializedShardDb = new SerializedShardDatabase(shardDb);
            Shard             = serializedShardDb;

            shardDb.Exists(true);
        }
Ejemplo n.º 2
0
        public static void ConsolidateBiotaGuids(uint startingGuid, bool tryNotToBreakPlugins, bool skipUserInputAfterWarning, out int numberOfBiotasConsolidated, out int numberOfBiotasSkipped, out int numberOfErrors)
        {
            log.Info($"Consolidating biotas, starting at guid 0x{startingGuid:X8}, tryNotToBreakPlugins: {tryNotToBreakPlugins}...");

            Thread.Sleep(1000); // Give the logger type to flush to the client so that our output lines up in order

            Console.WriteLine("!!! Do not proceed unless you have backed up your shard database first !!!");
            Console.WriteLine("In the event of any failure, you may be asked to rollback your shard database.");
            if (!skipUserInputAfterWarning)
            {
                Console.WriteLine("Press any key to proceed, or abort the process to quit.");
                Console.ReadLine();
            }
            Console.WriteLine(".... hold on to your butts...");

            if (startingGuid < ObjectGuid.DynamicMin)
            {
                throw new Exception($"startingGuid cannot be lower than ObjectGuid.DynamicMin (0x{ObjectGuid.DynamicMin:X8})");
            }

            int counter = 0;

            int numOfBiotasConsolidated = 0;
            int numOfBiotasSkipped      = 0;
            int numOfErrors             = 0;

            var shardDatabase = new ShardDatabase();

            var biotaCount = shardDatabase.GetBiotaCount();

            var          sequenceGaps = shardDatabase.GetSequenceGaps(ObjectGuid.DynamicMin, (uint)biotaCount);
            var          availableIDs = new LinkedList <(uint start, uint end)>(sequenceGaps);
            List <Biota> partialBiotas;

            using (var context = new ShardDbContext())
            {
                context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

                partialBiotas = context.Biota.Where(r => r.Id >= startingGuid).OrderByDescending(r => r.Id).ToList();
            }

            var idConversions = new ConcurrentDictionary <uint, uint>();

            // Process ConsolidatableBasicWeenieTypes first
            Parallel.ForEach(partialBiotas, ConfigManager.Config.Server.Threading.DatabaseParallelOptions, partialBiota =>
            {
                try
                {
                    if (numOfErrors > 0)
                    {
                        return;
                    }

                    if (!ConsolidatableBasicWeenieTypes.Contains((WeenieType)partialBiota.WeenieType))
                    {
                        return;
                    }

                    // Get the original biota
                    var fullBiota = shardDatabase.GetBiota(partialBiota.Id, true);

                    if (fullBiota == null)
                    {
                        Interlocked.Increment(ref numOfErrors);
                        log.Warn($"Failed to get biota with id 0x{partialBiota.Id:X8} from the database. This shouldn't happen. It also shouldn't require a rollback.");
                        return;
                    }

                    if (tryNotToBreakPlugins && MightBreakPlugins(fullBiota))
                    {
                        Interlocked.Increment(ref numOfBiotasSkipped);
                        return;
                    }

                    // Get the next available id
                    uint newId = 0;

                    lock (availableIDs)
                    {
                        if (availableIDs.First != null)
                        {
                            var id = availableIDs.First.Value.start;

                            if (availableIDs.First.Value.start == availableIDs.First.Value.end)
                            {
                                availableIDs.RemoveFirst();
                            }
                            else
                            {
                                availableIDs.First.Value = (availableIDs.First.Value.start + 1, availableIDs.First.Value.end);
                            }