Advertisement
UchihaT3Alo

Program To Get All Available Links For Conquer Clients

Jan 17th, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.96 KB | Source Code | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net.Http;
  4. using System.Threading.Tasks;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Program
  9.     {
  10.         private const int DefaultTimeout = 15000;
  11.         private static readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(DefaultTimeout) };
  12.  
  13.         static async Task Main()
  14.         {
  15.             Console.WriteLine("Choose the language you want to check:");
  16.             Console.WriteLine("1. Arabic");
  17.             Console.WriteLine("2. English");
  18.             Console.WriteLine("3. Spanish");
  19.             Console.WriteLine("4. Chinese");
  20.  
  21.             if (!int.TryParse(Console.ReadLine(), out int languageChoice) || languageChoice < 1 || languageChoice > 4)
  22.             {
  23.                 Console.WriteLine("Invalid language choice.");
  24.                 return;
  25.             }
  26.  
  27.             string baseUrl = GetBaseUrl(languageChoice);
  28.             int endNumber = GetEndNumber(languageChoice);
  29.             string namefile = GetFileName(languageChoice);
  30.  
  31.             using (var writer = new StreamWriter(namefile))
  32.             {
  33.                 for (int i = 0; i <= endNumber; i++)
  34.                 {
  35.                     string executableUrl = $"{baseUrl}{i:D4}.exe";
  36.                     string zipUrl = $"{baseUrl}{i:D4}.zip";
  37.  
  38.                     bool isExecutableResponseReceived = await IsReachableUrlAsync(executableUrl);
  39.                     bool isZipResponseReceived = await IsReachableUrlAsync(zipUrl);
  40.  
  41.                     if (isExecutableResponseReceived || isZipResponseReceived)
  42.                     {
  43.                         string receivedUrl = isExecutableResponseReceived ? executableUrl : zipUrl;
  44.                         Console.WriteLine($"Received a response from the URL: {receivedUrl}");
  45.                         writer.WriteLine(receivedUrl);
  46.                     }
  47.                     else
  48.                     {
  49.                         Console.WriteLine($"No response received for {i:D4}");
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             Console.WriteLine("Finished checking URLs.");
  55.             Console.ReadKey();
  56.         }
  57.  
  58.         private static string GetFileName(int languageChoice)
  59.         {
  60.             switch (languageChoice)
  61.             {
  62.                 case 1: return "Arabic Client Links.txt";
  63.                 case 2: return "English Client Links.txt";
  64.                 case 3: return "Spanish Client Links.txt";
  65.                 case 4: return "Chinese Client Links.txt";
  66.                 default: throw new ArgumentException("Invalid language choice.");
  67.             }
  68.         }
  69.  
  70.         private static string GetBaseUrl(int languageChoice)
  71.         {
  72.             switch (languageChoice)
  73.             {
  74.                 case 1: return "https://arconquer.download.99.com/ar_zf/Arabic_Conquer_v";
  75.                 case 2: return "https://codl.99.com/en_zf/Conquer_v";
  76.                 case 3: return "https://codl.99.com/sp_zf/Conquista_v";
  77.                 case 4: return "https://zfcdndownload.99.com/zf/zf_";
  78.                 default: throw new ArgumentException("Invalid language choice.");
  79.             }
  80.         }
  81.  
  82.         private static int GetEndNumber(int languageChoice)
  83.         {
  84.             switch (languageChoice)
  85.             {
  86.                 case 1: return 10000;
  87.                 case 2: return 10000;
  88.                 case 3: return 10000;
  89.                 case 4: return 10000;
  90.                 default: throw new ArgumentException("Invalid language choice.");
  91.             }
  92.         }
  93.  
  94.         private static async Task<bool> IsReachableUrlAsync(string url)
  95.         {
  96.             try
  97.             {
  98.                 using (var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
  99.                 {
  100.                     return response.IsSuccessStatusCode;
  101.                 }
  102.             }
  103.             catch (HttpRequestException)
  104.             {
  105.                 return false;
  106.             }
  107.         }
  108.  
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement