State types for systems and factions
コード例 #1
0
 public DockedEvent(DateTime timestamp, string system, string station, Superpower allegiance, string faction, State factionstate, Economy economy, Government government, SecurityLevel security) : base(timestamp, NAME)
 {
     this.system = system;
     this.station = station;
     this.allegiance = (allegiance == null ? Superpower.None.name : allegiance.name);
     this.faction = faction;
     this.factionstate = (factionstate == null ? State.None.name : factionstate.name);
     this.economy = (economy == null ? Economy.None.name : economy.name);
     this.government = (government == null ? Government.None.name : government.name);
     this.security = (security == null ? SecurityLevel.Low.name : security.name);
 }
コード例 #2
0
 public JumpedEvent(DateTime timestamp, string system, decimal x, decimal y, decimal z, decimal fuelused, decimal fuelremaining, Superpower allegiance, string faction, State factionstate, Economy economy, Government government, SecurityLevel security) : base(timestamp, NAME)
 {
     this.system = system;
     this.x = x;
     this.y = y;
     this.z = z;
     this.fuelused = fuelused;
     this.fuelremaining = fuelremaining;
     this.allegiance = (allegiance == null ? Superpower.None.name : allegiance.name) ;
     this.faction = faction;
     this.factionstate = (factionstate == null ? State.None.name : factionstate.name);
     this.economy = (economy == null ? Economy.None.name : economy.name);
     this.government = (government == null ? Government.None.name : government.name);
     this.security = (security == null ? SecurityLevel.None.name : security.name);
 }
コード例 #3
0
        public static State FromEDName(string from)
        {
            string tidiedFrom = from == null ? null : from.ToLowerInvariant();

            State result;
            if (from == null || from == "")
            {
                result = None;
            }
            else
            {
                result = STATES.FirstOrDefault(v => v.edname.ToLowerInvariant() == tidiedFrom);
            }
            if (result == null)
            {
                Logging.Report("Unknown State ED name " + from);
                result = new State(from, tidiedFrom);
            }
            return result;
        }
コード例 #4
0
        private CompanionAppService()
        {
            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)
                {
                    Logging.Warn("Failed to obtain profile: " + ex.ToString());
                }
            }
        }
コード例 #5
0
 /**
  * Try to relogin if there is some issue that requires it.
  * Throws an exception if it failed to log in.
  */
 private void relogin()
 {
     // Need to log in again.
     CurrentState = State.NEEDS_LOGIN;
     Login();
     if (CurrentState != State.READY)
     {
         Logging.Debug("Service in incorrect state to provide profile (" + CurrentState + ")");
         Logging.Debug("Leaving");
         throw new EliteDangerousCompanionAppIllegalStateException("Service in incorrect state to provide profile (" + CurrentState + ")");
     }
 }
コード例 #6
0
        ///<summary>Confirm a login.  Throws an exception if it fails</summary>
        public void Confirm(string code)
        {
            if (CurrentState != State.NEEDS_CONFIRMATION)
            {
                // Shouldn't be here
                throw new EliteDangerousCompanionAppIllegalStateException("Service in incorrect state to confirm login (" + CurrentState + ")");
            }

            HttpWebRequest request = GetRequest(BASE_URL + CONFIRM_URL);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
            string encodedCode = WebUtility.UrlEncode(code);
            byte[] data = Encoding.UTF8.GetBytes("code=" + encodedCode);
            request.ContentLength = data.Length;
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(data, 0, data.Length);
            }

            using (HttpWebResponse response = GetResponse(request))
            {
                if (response == null)
                {
                    throw new EliteDangerousCompanionAppException("Failed to contact API server");
                }

                if (response.StatusCode == HttpStatusCode.Found && response.Headers["Location"] == ROOT_URL)
                {
                    CurrentState = State.READY;
                }
                else if (response.StatusCode == HttpStatusCode.Found && response.Headers["Location"] == LOGIN_URL)
                {
                    CurrentState = State.NEEDS_LOGIN;
                    throw new EliteDangerousCompanionAppAuthenticationException("Confirmation code incorrect or expired");
                }
            }
        }