public CompanionAppService(bool enableDebugging = false) { this.enableDebugging = enableDebugging; Credentials = CompanionAppCredentials.FromFile(); // Need to work out our current state. //If we're missing username and password then we need to log in again if (String.IsNullOrEmpty(Credentials.email) || String.IsNullOrEmpty(Credentials.password)) { CurrentState = State.NEEDS_LOGIN; } else if (String.IsNullOrEmpty(Credentials.machineId) || String.IsNullOrEmpty(Credentials.machineToken)) { CurrentState = State.NEEDS_LOGIN; } else { // Looks like we're ready but test it to find out CurrentState = State.READY; try { Profile(); } catch (EliteDangerousCompanionAppException ex) { warn("Failed to obtain profile: " + ex.ToString()); } } }
public CompanionAppService(bool enableDebugging=false) { this.enableDebugging = enableDebugging; Credentials = CompanionAppCredentials.FromFile(); // Need to work out our current state. //If we're missing username and password then we need to log in again if (String.IsNullOrEmpty(Credentials.email) || String.IsNullOrEmpty(Credentials.password)) { CurrentState = State.NEEDS_LOGIN; } else if (String.IsNullOrEmpty(Credentials.machineId) || String.IsNullOrEmpty(Credentials.machineToken)) { CurrentState = State.NEEDS_LOGIN; } else { // Looks like we're ready but test it to find out CurrentState = State.READY; try { Profile(); } catch (EliteDangerousCompanionAppException ex) { // Ignored - current state will have been corrected by Profile() if we guessed incorrectly } } }
private static void AddCompanionAppCookie(CookieContainer cookies, CompanionAppCredentials credentials) { if (cookies != null && credentials.appId != null) { var appCookie = new Cookie(); appCookie.Domain = "companion.orerve.net"; appCookie.Path = "/"; appCookie.Name = "CompanionApp"; appCookie.Value = credentials.appId; appCookie.Secure = false; cookies.Add(appCookie); } }
private static void AddMachineTokenCookie(CookieContainer cookies, CompanionAppCredentials credentials) { if (cookies != null && credentials.machineToken != null) { var machineTokenCookie = new Cookie(); machineTokenCookie.Domain = "companion.orerve.net"; machineTokenCookie.Path = "/"; machineTokenCookie.Name = "mtk"; machineTokenCookie.Value = credentials.machineToken; machineTokenCookie.Secure = true; // The expiry is embedded in the cookie value DateTime expiryDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); expiryDateTime = expiryDateTime.AddSeconds(Convert.ToInt64(credentials.machineToken.Substring(0, credentials.machineToken.IndexOf("%7C")))); machineTokenCookie.Expires = expiryDateTime; cookies.Add(machineTokenCookie); } }
/// <summary> /// Obtain credentials from a file. If the file name is not supplied the the default /// path of %APPDATA%\EDDI\credentials.json is used /// </summary> public static CompanionAppCredentials FromFile(string filename = null) { if (filename == null) { String dataDir = Environment.GetEnvironmentVariable("AppData") + "\\EDDI"; Directory.CreateDirectory(dataDir); filename = dataDir + "\\credentials.json"; } CompanionAppCredentials credentials; try { String credentialsData = File.ReadAllText(filename); credentials = JsonConvert.DeserializeObject <CompanionAppCredentials>(credentialsData); } catch { credentials = new CompanionAppCredentials(); } credentials.dataPath = filename; return(credentials); }
/// <summary> /// Obtain credentials from a file. If the file name is not supplied the the default /// path of %APPDATA%\EDDI\credentials.json is used /// </summary> public static CompanionAppCredentials FromFile(string filename=null) { if (filename == null) { String dataDir = Environment.GetEnvironmentVariable("AppData") + "\\EDDI"; Directory.CreateDirectory(dataDir); filename = dataDir + "\\credentials.json"; } CompanionAppCredentials credentials; try { String credentialsData = File.ReadAllText(filename); credentials = JsonConvert.DeserializeObject<CompanionAppCredentials>(credentialsData); } catch { credentials = new CompanionAppCredentials(); } credentials.dataPath = filename; return credentials; }