using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using NostaleAuth.Extensions; using NostaleAuth.Models; using NostaleAuth.Utils; namespace NostaleAuth.Api { public class GameforgeApi { private readonly HttpClient _httpClient; public GameforgeApi() { _httpClient = new HttpClient(); } public Guid GenerateIntallationId(string email, string password) { return Guid.Parse(Cryptography.ToMd5(email + password)); } public async Task GetLatestVersion() { var request = new GameforgeRequest(HttpMethod.Get, "/patching/download/nostale/default?branchToken"); Dictionary response = await request.Send(); return response.GetValueOrDefault("latest"); } public async Task Login(string email, string password, Locales locale, Guid installationId) { var request = new GameforgeRequest(HttpMethod.Post, "/auth/sessions", installationId); var authRequest = new AuthRequest { Locale = locale.Value, Email = email, Password = password }; Dictionary response = await request.Send(authRequest); if (response == null) { return null; } string authToken = response.GetValueOrDefault("token") ?? string.Empty; return new AuthorizedGameforgeApi(authToken, installationId); } public Task Login(string email, string password, Locales locale) { return Login(email, password, locale, GenerateIntallationId(email, password)); } } }