nttl050611 commited on
Commit
f4bef29
·
1 Parent(s): 224c61b

Create LauncherConfig.cs

Browse files
Files changed (1) hide show
  1. LauncherConfig.cs +115 -0
LauncherConfig.cs ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.Net.Http;
3
+ using System.Threading.Tasks;
4
+ using Newtonsoft.Json;
5
+
6
+ namespace ZerionLauncher.Services
7
+ {
8
+ /// <summary>
9
+ /// Giá trị mặc định khi không tải được config từ host (offline / host chết).
10
+ /// Giữ nguyên giá trị production hiện tại để launcher vẫn chạy được.
11
+ /// </summary>
12
+ public class RemoteConfigData
13
+ {
14
+ [JsonProperty("apiBaseUrl")]
15
+ public string ApiBaseUrl { get; set; } = "https://api-production-20fe.up.railway.app/api/v1";
16
+
17
+ [JsonProperty("newsUrl")]
18
+ public string NewsUrl { get; set; } = "https://huggingface.co/datasets/nttl050611/LauncherPC/raw/main/news.json";
19
+
20
+ [JsonProperty("manifestUrl")]
21
+ public string ManifestUrl { get; set; } = "https://huggingface.co/datasets/nttl050611/LauncherPC/resolve/main/manifest.json";
22
+
23
+ [JsonProperty("playersUrl")]
24
+ public string PlayersUrl { get; set; } = "http://15.235.149.123/players.json";
25
+
26
+ [JsonProperty("autoUpdaterXmlUrl")]
27
+ public string AutoUpdaterXmlUrl { get; set; } = "https://raw.githubusercontent.com/ntl050611/gta/refs/heads/main/autoupdater.xml";
28
+
29
+ [JsonProperty("launcherReleaseApiUrl")]
30
+ public string LauncherReleaseApiUrl { get; set; } = "https://api.github.com/repos/ntl050611/gta/releases/latest";
31
+
32
+ [JsonProperty("payloadEndpoint")]
33
+ public string PayloadEndpoint { get; set; } = "http://127.0.0.1:3000/api/v1/security/payload";
34
+
35
+ [JsonProperty("payloadEncryptionKeyHex")]
36
+ public string PayloadEncryptionKeyHex { get; set; } = "0000000000000000000000000000000000000000000000000000000000000000";
37
+
38
+ [JsonProperty("discordInviteUrl")]
39
+ public string DiscordInviteUrl { get; set; } = "https://discord.gg/X63Zbz99j8";
40
+
41
+ [JsonProperty("websiteUrl")]
42
+ public string WebsiteUrl { get; set; } = "https://dinhcaotdm.net";
43
+
44
+ [JsonProperty("fanpageUrl")]
45
+ public string FanpageUrl { get; set; } = "https://fb.dinhcaotdm.net";
46
+
47
+ [JsonProperty("registerUrl")]
48
+ public string RegisterUrl { get; set; } = "https://zerion.vn/register";
49
+
50
+ [JsonProperty("accountUrl")]
51
+ public string AccountUrl { get; set; } = "https://zerion.vn/account";
52
+ }
53
+
54
+ /// <summary>
55
+ /// Tải cấu hình từ host ngay khi launcher khởi động. Mọi URL / key / IP / port
56
+ /// được lấy từ đây — muốn đổi server chỉ cần sửa file launcher-config.json trên
57
+ /// host, không cần build lại launcher. Nếu fetch thất bại thì dùng giá trị
58
+ /// mặc định trong RemoteConfigData.
59
+ /// </summary>
60
+ public static class RemoteConfig
61
+ {
62
+ // ⚠️ Đây là URL duy nhất còn hardcode — bỏ file launcher-config.json cạnh nó.
63
+ private const string ConfigUrl =
64
+ "https://huggingface.co/datasets/nttl050611/LauncherPC/raw/main/launcher-config.json";
65
+
66
+ private static readonly HttpClient _http = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
67
+
68
+ private static RemoteConfigData _current = new RemoteConfigData();
69
+ private static bool _loaded = false;
70
+
71
+ public static RemoteConfigData Current => _current;
72
+
73
+ public static async Task LoadAsync()
74
+ {
75
+ if (_loaded) return;
76
+ _loaded = true;
77
+
78
+ try
79
+ {
80
+ string json = await _http.GetStringAsync(ConfigUrl).ConfigureAwait(false);
81
+ var parsed = JsonConvert.DeserializeObject<RemoteConfigData>(json);
82
+ if (parsed != null)
83
+ {
84
+ _current = MergeWithDefaults(parsed);
85
+ }
86
+ }
87
+ catch
88
+ {
89
+ // Mạng lỗi / host lỗi — giữ nguyên mặc định, launcher vẫn chạy.
90
+ }
91
+ }
92
+
93
+ /// <summary>Trường nào host để trống thì giữ giá trị mặc định.</summary>
94
+ private static RemoteConfigData MergeWithDefaults(RemoteConfigData fetched)
95
+ {
96
+ var fallback = new RemoteConfigData();
97
+
98
+ if (string.IsNullOrWhiteSpace(fetched.ApiBaseUrl)) fetched.ApiBaseUrl = fallback.ApiBaseUrl;
99
+ if (string.IsNullOrWhiteSpace(fetched.NewsUrl)) fetched.NewsUrl = fallback.NewsUrl;
100
+ if (string.IsNullOrWhiteSpace(fetched.ManifestUrl)) fetched.ManifestUrl = fallback.ManifestUrl;
101
+ if (string.IsNullOrWhiteSpace(fetched.PlayersUrl)) fetched.PlayersUrl = fallback.PlayersUrl;
102
+ if (string.IsNullOrWhiteSpace(fetched.AutoUpdaterXmlUrl)) fetched.AutoUpdaterXmlUrl = fallback.AutoUpdaterXmlUrl;
103
+ if (string.IsNullOrWhiteSpace(fetched.LauncherReleaseApiUrl)) fetched.LauncherReleaseApiUrl = fallback.LauncherReleaseApiUrl;
104
+ if (string.IsNullOrWhiteSpace(fetched.PayloadEndpoint)) fetched.PayloadEndpoint = fallback.PayloadEndpoint;
105
+ if (string.IsNullOrWhiteSpace(fetched.PayloadEncryptionKeyHex)) fetched.PayloadEncryptionKeyHex = fallback.PayloadEncryptionKeyHex;
106
+ if (string.IsNullOrWhiteSpace(fetched.DiscordInviteUrl)) fetched.DiscordInviteUrl = fallback.DiscordInviteUrl;
107
+ if (string.IsNullOrWhiteSpace(fetched.WebsiteUrl)) fetched.WebsiteUrl = fallback.WebsiteUrl;
108
+ if (string.IsNullOrWhiteSpace(fetched.FanpageUrl)) fetched.FanpageUrl = fallback.FanpageUrl;
109
+ if (string.IsNullOrWhiteSpace(fetched.RegisterUrl)) fetched.RegisterUrl = fallback.RegisterUrl;
110
+ if (string.IsNullOrWhiteSpace(fetched.AccountUrl)) fetched.AccountUrl = fallback.AccountUrl;
111
+
112
+ return fetched;
113
+ }
114
+ }
115
+ }