Ejemplo n.º 1
0
        /// <summary>
        /// Request a file from the CDN.
        /// </summary>
        /// <param name="url"></param>
        public static MemoryStream RequestCDN(string url)
        {
            var client = new HttpClient();

            try
            {
                foreach (var cdn in cdnUrls)
                {
                    var response = client.GetAsync($"{cdn}/{url}").Result;

                    if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
                    {
                        return(new MemoryStream(response.Content.ReadAsByteArrayAsync().Result));
                    }
                    else
                    {
                        DiscordServer.Log($"{cdn}/{url} gave error code {response.StatusCode} ({(uint)response.StatusCode})", true);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                DiscordServer.Log(ex.ToString(), true);

                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process the newly added files and automatically name them.
        /// </summary>
        public static void ProcessFiles(string product, List <RootEntry> entries, string buildConfig, string cdnConfig, uint buildId)
        {
            // Read the original listfile first.
            ReadOriginalListfile();

            Console.WriteLine("Opening CASC Storage..");
            CASC.OpenCasc(product, buildConfig, cdnConfig);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            Console.WriteLine($"Processing {entries.Count} root entries");
            foreach (var entry in entries)
            {
                using (var reader = CASC.OpenFile(entry.FileDataId))
                {
                    if (reader == null)
                    {
                        return;
                    }

                    var chunkId = (Chunk)reader.ReadUInt32().FlipUInt();
                    if (chunkId == Chunk.MD21)
                    {
                        reader.BaseStream.Position = 0;
                        var m2Reader = new M2Reader(reader);
                        var pathName = Names.GetPathFromName(m2Reader.GetName());

                        AddToListfile(entry.FileDataId, $"{pathName}/{m2Reader.GetName()}.m2");

                        // Name all the files.
                        m2Reader.NameAllFiles();
                    }

                    // Close the streams to save memory.
                    reader.Close();
                }
            }

            stopWatch.Stop();
            Console.WriteLine($"Finished processing {entries.Count} root entries in {stopWatch.Elapsed}\n");

            // Diff the 2 Map.db2 files.
            if (product == "wow_beta")
            {
                var oldMapStorage = new DBReader(CASC.OldStorage.OpenFile(1349477)).GetRecords <Map>();
                var newMapStorage = new DBReader(CASC.NewStorage.OpenFile(1349477)).GetRecords <Map>();

                if (oldMapStorage.Count < newMapStorage.Count)
                {
                    DiscordServer.Log("Diffing Map.db2 for new map entries...");

                    foreach (var entry in newMapStorage)
                    {
                        if (!oldMapStorage.ContainsKey(entry.Key))
                        {
                            if (entry.Value.WdtFileDataId != 0)
                            {
                                var wdt = new WDTReader();
                                wdt.ReadWDT(CASC.NewStorage, entry.Value.WdtFileDataId);

                                AddToListfile(entry.Value.WdtFileDataId, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}.wdt");
                                foreach (var maid in wdt.MAIDs)
                                {
                                    AddToListfile(maid.Value.RootADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.adt");
                                    AddToListfile(maid.Value.Obj0ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_obj0.adt");
                                    AddToListfile(maid.Value.Obj1ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_obj1.adt");
                                    AddToListfile(maid.Value.Tex0ADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_tex0.adt");
                                    AddToListfile(maid.Value.LodADT, $"world/maps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_lod.adt");
                                    AddToListfile(maid.Value.MapTexture, $"world/maptextures/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.blp");
                                    AddToListfile(maid.Value.MapTextureN, $"world/maptextures/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}_n.blp");
                                    AddToListfile(maid.Value.MinimapTexture, $"world/minimaps/{entry.Value.Directory}/{entry.Value.Directory}_{maid.Key}.blp");
                                }
                            }
                        }
                    }
                }
            }

            // Generate the listfile now.
            GenerateListfile(buildId);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // Initialize Discord
            DiscordServer.Initialize();

            // Getting all the files in "cache"
            foreach (var file in Directory.GetFiles("cache/"))
            {
                var filenameSplit = file.Split("_").ToList();
                filenameSplit.RemoveAt(filenameSplit.IndexOf(filenameSplit.Last()));

                var product = string.Join('_', filenameSplit);
                ParseVersions(Path.GetFileName(product), file);
            }

            using (var client = new Client(Region.US))
            {
                var summary = Ribbit.ParseSummary(client.Request("v1/summary").ToString());
                foreach (var entry in summary)
                {
                    if (entry.Key.Type == "cdn" || entry.Key.Type == "bgdl" || !entry.Key.Product.StartsWith("wow"))
                    {
                        continue;
                    }

                    products.Add(entry.Key.Product);

                    // Request the product versions file.
                    var request = client.Request($"v1/products/{entry.Key.Product}/versions").ToString();

                    // Parse the version file.
                    File.WriteAllText("cache/temp", request);
                    ParseVersions(entry.Key.Product, "cache/temp");
                    File.Delete("cache/temp");

                    // Cache the file
                    File.WriteAllText($"cache/{entry.Key.Product}_{versionsIds[entry.Key.Product]}", request);

                    Thread.Sleep(100);
                }

                if (isMonitoring)
                {
                    DiscordServer.Log("Monitoring the patch servers...");
                }

                while (isMonitoring)
                {
                    Thread.Sleep(60000);

                    foreach (var product in products)
                    {
                        // Request the product versions file.
                        var request = client.Request($"v1/products/{product}/versions").ToString();

                        // Parse the version file.
                        File.WriteAllText("cache/temp", request);
                        ParseVersions(product, "cache/temp");
                        File.Delete("cache/temp");

                        Thread.Sleep(100);
                    }
                }
            }
        }