コード例 #1
0
        public Alerts(IConfiguration configuration, IMeCache meCache, ILogging logging)
        {
            _logging = logging;

            try
            {
                _synthesizer = new SpeechSynthesizer();
            }
            catch (Exception)
            {
                _logging.LogMessage("Alerts", "Initialize", LogSeverityTypes.Standard,
                                    "Unable to initialize SpeechSynthesizer. Text-to-Speech alerts will not be available.");
                _canSpeak = false;
                _disposed = true;
                return;
            }

            _configuration = configuration;
            _meCache       = meCache;

            //Attach an eventhandler for speakCompleted and set the volume of the synth to max
            _synthesizer.SpeakCompleted += synthesizer_SpeakCompleted;
            _synthesizer.Volume          = 100;

            //Make sure we get disposed
            ModuleManager.ModulesToDispose.Add(this);
        }
コード例 #2
0
        public void MakeCargoHoldActive()
        {
            var methodName = "MakeCargoHoldActive";

            _logging.LogTrace(this, methodName);

            var cargoHoldWindow = GetCargoHoldWindow();

            if (cargoHoldWindow == null || !cargoHoldWindow.IsValid)
            {
                _logging.LogMessage(this, methodName, LogSeverityTypes.Debug, "Error: Cargo hold window was null or invalid.");
                return;
            }

            cargoHoldWindow.MakeActive();
        }
コード例 #3
0
        protected virtual void Initialize(LSEventArgs copy)
        {
            var methodName = "Initialize";

            Int64 sendingFleetMemberId;
            int   solarSystemId;

            if (!Int64.TryParse(copy.Args[0], out sendingFleetMemberId))
            {
                _logging.LogMessage(ObjectName, methodName, LogSeverityTypes.Standard, "Unable to parse sending fleet member ID {0}",
                                    copy.Args[0]);
            }

            if (!int.TryParse(copy.Args[1], out solarSystemId))
            {
                _logging.LogMessage(ObjectName, methodName, LogSeverityTypes.Standard, "Unable to parse sending solar system ID {0}",
                                    copy.Args[1]);
            }

            SendingFleetMemberCharId = sendingFleetMemberId;
            SolarSystemId            = solarSystemId;
        }
コード例 #4
0
        /// <summary>
        /// EventHandler method for the ISXEVE_onFrame LS event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void HandleEveFrame(object sender, LSEventArgs e)
        {
            using (new FrameLock(true))
            {
                //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Beginning frame handler.");

                //Reset the exitResetEvent. We should not attempt to dispose right now.
                _exitResetEvent.Reset();

                //If paused, stop the runtime timer.
                if (!IsEnabled)
                {
                    RunTime.Stop();
                }

                //If doing cleanup go ahead and and do cleanup.
                if (_isDoingInFrameCleanup)
                {
                    //Have ModuleManager do inframe cleanup and set the event
                    //ModuleManager.InFrameCleanup();

                    _isDoingInFrameCleanup = false;
                    _InFrameCleanupResetEvent.Set();
                }

                //If not paused and it's been enough time to pulse again...
                if (Instance.IsEnabled && DateTime.Now.CompareTo(NextPulse) >= 0)
                {
                    //Make sure the runtime timer is running.
                    RunTime.Start();

                    //Now, if it's not been enough pulses to fire the pulse...
                    if (!Instance.ShouldPulse())
                    {
                        //Set the reset event and return.
                        EndPulse();
                        return;
                    }

                    var methodName = "HandleEveFrame";

                    //Set the time of this pulse
                    TimeOfPulse = DateTime.Now;
                    //Increment the pulse count
                    Pulses++;
                    //Core.StealthBot.Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                    //	"HandleEveFrame", String.Format("Pulse check: {0}", Pulses)));

                    #region ISXEVE IsSafe Check

                    //If ISXEve is reporting unsafe, just abort and return. It means
                    //it's not safe to continue logic checks with ISXEVE.
                    if (!_isxeveProvider.Isxeve.IsSafe)
                    {
                        //Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                        //methodName, "Error: ISXEVE reporting not safe. Aborting pulse."));
                        EndPulse();
                        return;
                    }

                    #endregion

                    #region ISXEVE Detection

                    if (!_isxeveProvider.Isxeve.IsReady)
                    {
                        Instance.LogMessage(methodName, LogSeverityTypes.Debug, "ISXEVE is not ready, pausing.");
                        Instance.IsEnabled = false;
                        EndPulse();
                        return;
                    }

                    #endregion

                    #region Me Validity Check

                    //Another check - ME validity
                    if (!MeCache.CheckValidity())
                    {
                        //Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                        //methodName, "Error: InSpace and InStation both false or Me invalid."));

                        if (LavishScriptObject.IsNullOrInvalid(MeCache.Me))
                        {
                            #region Login Screen Detection

                            var login = new Login();
                            if (!LavishScriptObject.IsNullOrInvalid(login))
                            {
                                if (ConfigurationManager.ActiveConfigProfile != null)
                                {
                                    Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                        "Login screen detected. Exiting, relaunching if enabled.");
                                    Instance.ExitAndRelaunch();
                                }
                                else
                                {
                                    Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                        "Login screen detected. Please close StealthBot, restart EVE, and start StealthBot while fully logged in.");
                                }
                                Instance.IsEnabled = false;
                            }

                            #endregion

                            #region CharSelect Screen Detection

                            var charSelect = new CharSelect();
                            if (!LavishScriptObject.IsNullOrInvalid(charSelect))
                            {
                                Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                    "Character Select screen detected. Please close StealthBot, restart EVE, and start StealthBot while fully logged in.");
                                Instance.IsEnabled = false;
                            }

                            #endregion
                        }

                        _exitResetEvent.Set();
                        Logging.LogMessage("StealthBot", methodName, LogSeverityTypes.Debug, "Aborting pulse due to invalidity.");
                        NextPulse = DateTime.Now.AddSeconds(PULSE_FREQUENCY);
                        return;
                    }

                    #endregion

                    //Pulse the ModuleManager.
                    ModuleManager.Pulse();

                    //Fire off the OnPulse event to let the UI know of any changes
                    try
                    {
                        //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Beginning OnPulse.");
                        //Instance.StartMethodProfiling("OnPulse");
                        OnPulse(sender, e);
                        //Instance.EndMethodProfiling();
                        //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Ending OnPulse.");
                    }
                    catch (Exception ex)
                    {
                        LogException(ex, methodName, "Caught excpetion while firing OnPulse event:");
                    }

                    EndPulse();
                }

                //We're done; set the reset event so we can dispose if necessary.
                _exitResetEvent.Set();
                //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Ending EVE Frame.");
            }
        }
コード例 #5
0
 protected void LogMessage(string sendingMethod, LogSeverityTypes logSeverity, string messageFormat, params object[] messageParameters)
 {
     _logging.LogMessage(ModuleName, sendingMethod, logSeverity, messageFormat, messageParameters);
 }
コード例 #6
0
ファイル: Safespots.cs プロジェクト: isxGames/StealthBot
        /// <summary>
        /// Determine if we are currently safe from harm
        /// </summary>
        /// <returns></returns>
        public bool IsSafe()
        {
            var methodName = "IsSafe";

            //If we're in a station, we are safe.
            if (_meCache.InStation)
            {
                return(true);
            }

            //If we're in a tower bubble, we're safe.
            var controlTowers = _entityProvider.EntityWrappers.Where(e => e.GroupID == (int)GroupIDs.ControlTower); // Max tower shield range

            foreach (var controlTower in controlTowers)
            {
                var itemInfo = _isxeveProvider.Eve.ItemInfo(controlTower.TypeID);

                _logging.LogMessage(ClassName, methodName, LogSeverityTypes.Debug, "ShieldRadius: {0}, Tower distance: {1}",
                                    itemInfo.ShieldRadius, controlTower.Distance);

                if (itemInfo.ShieldRadius > 0 && controlTower.Distance <= itemInfo.ShieldRadius)
                {
                    _logging.LogMessage(ClassName, methodName, LogSeverityTypes.Debug, "We are within shield radius {0} to control tower {1} ({2}).",
                                        itemInfo.ShieldRadius, controlTower.Name, controlTower.ID);
                    return(true);
                }
            }

            //Alright, we're in space. Are we within warp range of a safe bookmark?
            var safeBookMarksInSystem = GetSafeBookMarksInSystem();

            //If I have safe bookmarks, I should never ever be able to consider a planet safe. I should be moving at a safe bookmark.
            //So - if I have bookmarks { if I'm at one, I'm safe, otherwise I'm not safe }
            var isAtSafeBookMark = safeBookMarksInSystem.Any(bm => _mathUtility.Distance(bm.X, bm.Y, bm.Z, _meToEntityCache.X, _meToEntityCache.Y, _meToEntityCache.Z) < (int)Ranges.Warp);

            var localIsSafeOrICanCloak = _social.IsLocalSafe || (_ship.CloakingDeviceModules.Any() && !_entityProvider.EntityWrappers.Any(e => e.IsTargetingMe));

            if (isAtSafeBookMark && localIsSafeOrICanCloak)
            {
                _logging.LogMessage(ClassName, methodName, LogSeverityTypes.Debug, "We are within warp range of a safe bookmark and local is safe or we can cloak.");
                return(true);
            }

            //Only consider planets safe spots if there are no safe bookmarks or stations
            var stationEntities = _entityProvider.EntityWrappers.Where(e => e.GroupID == (int)GroupIDs.Station);

            if (!safeBookMarksInSystem.Any() && !stationEntities.Any())
            {
                //If there were no safe bookmarks in this system, we can consider ourselves at a safe-spot at a planet warp-in
                var planetWithinPlanetWarpRange = _entityProvider.EntityWrappers
                                                  .FirstOrDefault(e => e.GroupID == (int)GroupIDs.Planet && e.Distance <= (long)Ranges.PlanetWarpIn);

                if (planetWithinPlanetWarpRange != null && localIsSafeOrICanCloak)
                {
                    _logging.LogMessage(ClassName, methodName, LogSeverityTypes.Debug, "We are within planet warpin range of planet \"{0}\" ({1}, {2}) and local is safe or we can cloak.",
                                        planetWithinPlanetWarpRange.Name, planetWithinPlanetWarpRange.ID, planetWithinPlanetWarpRange.Distance);
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Do the Login process.
        /// </summary>
        /// <param name="authStateInfo">Reference to an AuthStateInfo instance containing login info</param>
        private void Login(AuthStateInfo authStateInfo)
        {
            //Used as the y value in key calculations
            BigInteger randomBigInteger = null;

            //Used as the client public key (v) for the server to derive the secret key with
            BigInteger clientPublicKey = null;
            //Calculated secret key used for encryption
            BigInteger sessionKey = null;

            //The caluclations have a nasty habit of giving non-64-byte numbers, so re-calculate as
            //necessary 'til they're all 64-bytes long
            while ((object)randomBigInteger == null || randomBigInteger.ToHexString().Length != 64 ||
                   ((object)clientPublicKey == null || clientPublicKey.ToHexString().Length != 64) ||
                   ((object)sessionKey == null || sessionKey.ToHexString().Length != 64))
            {
                randomBigInteger = GetRandomBigInteger(_modulus);

                //v = g^y mod p
                clientPublicKey = _generator.modPow(randomBigInteger, _modulus);

                //secret key = [server public key]^y mod p
                sessionKey = _serverPublicKey.modPow(randomBigInteger, _modulus);
            }

            //Create the userInfoString which will be encrypted and transmitted to the auth server
            var userInfoString = string.Format("{0} {1}", authStateInfo.AuthParams.Username, authStateInfo.AuthParams.Password);
            //Get a byte[] representing the userInfoString
            var userInfoBytes = Encoding.ASCII.GetBytes(userInfoString);

            // Key and iv for encryption
            // Key is the sessionKey in Hex
            string key = sessionKey.ToHexString();
            // iv is the
            string iv = _modulus.ToHexString().Substring(0, 32);

            //Get the encrypted user info bytes using our key and IV
            var encryptedUserInfoBytes = EncryptBytes(userInfoBytes, key, iv);

            //Get the byte[] for our hardware hash
            var hardwareHashBytes = GenerateHardwareHash();
            //Get the encrypted bytes for the hardware hash
            var encryptedHardwareHashBytes = EncryptBytes(hardwareHashBytes, key, iv);

            //Convert the encrypted byte[]s into Base64-strings, then url-encode them
            string encryptedHardwareHashString = System.Web.HttpUtility.UrlEncode(
                Convert.ToBase64String(encryptedHardwareHashBytes)),
                   encryptedUserInfoString = System.Web.HttpUtility.UrlEncode(
                Convert.ToBase64String(encryptedUserInfoBytes));

            //Get the hex string of the public key
            var clientPublicKeyString = clientPublicKey.ToHexString();

            //Try to authenticate with each auth server until we have a successful one.
            foreach (var serverUrl in AUTH_SERVERS)
            {
                var formattedUrl = string.Format("{0}?a={1}&b={2}&c={3}",
                                                 serverUrl, clientPublicKeyString, encryptedUserInfoString, encryptedHardwareHashString);
                _logging.LogMessage("Authentication", "Authenticate", LogSeverityTypes.Debug, "Request URL: {0}", formattedUrl);

                //Try to authenticate and save the result
                var authResult = Authenticate(formattedUrl, key, iv);

                //Firstly, if it was bad response, just re-try.
                if (authResult.AuthenticationResult == ERROR_BAD_RESPONSE)
                {
                    authResult = Authenticate(formattedUrl, key, iv);
                }

                //If the connection succeeded...
                if (authResult.DidAuthenticationFail)
                {
                    //Fire the event with the login result.
                    if (AuthenticationComplete != null)
                    {
                        AuthenticationComplete(authResult, authResult);
                    }
                    //We're done with auth; return
                    return;
                }
            }

            //If we didn't successfully connect, fire event with an auth result stating so.
            _logging.LogMessage("Authentication", "Login", LogSeverityTypes.Debug, "Last chance return");
            var loginResult = new __err_retn(false, ERROR_UNKNOWN, false);

            if (AuthenticationComplete != null)
            {
                AuthenticationComplete(loginResult, loginResult);
            }
        }