Beispiel #1
0
        /// <summary>
        /// Send a request to the homepage of steam, check if there is something with "profiles/OurSteamID64/friends"
        /// If there is such a content inside the string, then we are still authenticated return true, so we know we are loggedon
        /// If there is not such a content inside the string, then we are not authenticated and try to authenticate to the web again
        /// To authenticate we have to request a new nonce, which will be needed to authenticate
        /// </summary>
        /// <returns></returns>
        public async Task <bool> RefreshSessionIfNeeded()
        {
            string response = await m_WebHelper.GetStringFromRequest("http://steamcommunity.com/my/").ConfigureAwait(false);

            bool isNotLoggedOn = response.Contains("Sign In");

            if (isNotLoggedOn)
            {
                SteamUser.WebAPIUserNonceCallback userNonceCallback;

                try
                {
                    userNonceCallback = await m_steamUser.RequestWebAPIUserNonce();
                }
                catch (Exception e)
                {
                    m_logger.Error(e.Message);
                    return(false);
                }

                if (string.IsNullOrEmpty(userNonceCallback?.Nonce))
                {
                    m_logger.Warning("Usernonce is empty");
                }

                m_logger.Warning("Reauthenticating...");

                return(AuthenticateUser(m_steamClient, userNonceCallback?.Nonce));
            }
            else
            {
                return(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// If we didn't link our mobile via the bot, just return a message
        /// If we did link our mobile via the bot, we have to get the SteamLogin and SteamLoginSecure, which we get from logging in to the web
        /// Pass the sessionID because we need it aswell, generate a uint64 SteamID from the SessionID, without this we can't fetch the confirmations
        /// With these values we can get all confirmations and accept or deny them, without it will throw errors
        /// </summary>
        public async Task ConfirmAllTrades(string _steamLogin, string _steamLoginSecure, string _sessionID)
        {
            if (m_steamGuardAccount == null)
            {
                m_logger.Warning("Bot account does not have 2FA enabled.");
            }
            else
            {
                m_steamGuardAccount.Session = new SessionData
                {
                    SteamLogin       = _steamLogin,
                    SteamLoginSecure = _steamLoginSecure,
                    SessionID        = _sessionID,
                    SteamID          = new SteamID(Encoding.UTF8.GetString(Convert.FromBase64String(_sessionID))).ConvertToUInt64()
                };

                bool           hasToRelog    = false;
                Confirmation[] confirmations = null;

                try
                {
                    confirmations = await m_steamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false);
                }
                catch (SteamGuardAccount.WGTokenInvalidException exception)
                {
                    hasToRelog = true;
                }

                if (confirmations != null)
                {
                    foreach (Confirmation confirmation in confirmations)
                    {
                        bool confirmedTrade = m_steamGuardAccount.AcceptConfirmation(confirmation);

                        if (confirmedTrade)
                        {
                            m_logger.Info($"Confirmed {confirmation.Key}, {confirmation.IntType}/{confirmation.Creator}(Confirmation ID #{confirmation.ID})");
                        }
                        else
                        {
                            m_logger.Warning($"Could not confirm {confirmation.Key}, (Confirmation ID #{confirmation.ID})");
                        }
                    }
                }
                else
                {
                    if (hasToRelog)
                    {
                        await m_steamGuardAccount.RefreshSessionAsync().ConfigureAwait(false);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Check if the tradeoffer is sent from an admin, if so, accept it and throw a marked message, else move on
        /// </summary>
        /// <param name="_steamFriendsHelper"></param>
        /// <param name="_tradeOffer"></param>
        /// <param name="_tradePartnerID"></param>
        /// <returns></returns>
        private async Task <bool> AdminTradeOffer(SteamFriendsHelper _steamFriendsHelper, TradeOffer _tradeOffer, SteamID _tradePartnerID)
        {
            if (_steamFriendsHelper.IsBotAdmin(_tradePartnerID, m_botInfo.Admins))
            {
                if (await m_tradeOfferWebAPI.AcceptTradeOffer(_tradeOffer.TradeOfferID).ConfigureAwait(false))
                {
                    m_logger.Warning($"Tradeoffer {_tradeOffer.TradeOfferID} was sent by admin {_tradePartnerID.ConvertToUInt64()}");
                }

                return(true);
            }

            return(false);
        }
Beispiel #4
0
        protected override bool ShouldRetryOn(Exception exception)
        {
            var logger = new Logger.Logger();

            logger.Warning(exception, "ALARM{0}", Environment.NewLine);

            return(true);
        }
Beispiel #5
0
 static void Main(string[] args)
 {
     Logger.Logger logger = Logger.Loggers.LogFactory.GetLogger();
     logger.Error("I'm a small bug");
     logger.Info("I can be useful");
     logger.Warning("Nobody looks at warnings(");
     logger.Error(new StackOverflowException());
 }
Beispiel #6
0
        /// <summary>
        /// If we didn't link our mobile via the bot, just return a message
        /// If we did link our mobile via the bot, we have to get the SteamLogin and SteamLoginSecure, which we get from logging in to the web
        /// Pass the sessionID because we need it aswell, generate a uint64 SteamID from the SessionID, without this we can't fetch the confirmations
        /// With these values we can get all confirmations and accept or deny them, without it will throw errors
        /// </summary>
        public void ConfirmAllTrades(string _steamLogin, string _steamLoginSecure, string _sessionID)
        {
            if (m_steamGuardAccount == null)
            {
                m_logger.Warning("Bot account does not have 2FA enabled.");
            }
            else
            {
                m_steamGuardAccount.Session = new SessionData
                {
                    SteamLogin       = _steamLogin,
                    SteamLoginSecure = _steamLoginSecure,
                    SessionID        = _sessionID,
                    SteamID          = new SteamID(Encoding.UTF8.GetString(Convert.FromBase64String(_sessionID))).ConvertToUInt64()
                };

                Confirmation[] confirmations = m_steamGuardAccount.FetchConfirmations();

                if (confirmations != null)
                {
                    foreach (Confirmation confirmation in confirmations)
                    {
                        bool confirmedTrade = m_steamGuardAccount.AcceptConfirmation(confirmation);

                        if (confirmedTrade)
                        {
                            m_logger.Info($"Confirmed {confirmation.Description}, (Confirmation ID #{confirmation.ID})");
                        }
                        else
                        {
                            m_logger.Warning($"Could not confirm {confirmation.Description}, (Confirmation ID #{confirmation.ID})");
                        }
                    }
                }
                else
                {
                    m_logger.Error("Mobilehelper: Must Login");
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Get tradeoffers with specific information
 /// </summary>
 public KeyValue GetTradeOffersInterface(bool _getSentOffers, bool _getReceivedOffers, bool _getDescription, bool _activeOnly, bool _historicalOnly)
 {
     // Reuqest the IEconService with our apikey
     using (dynamic IEconService = WebAPI.GetInterface(IEconServiceInterface, m_steamWeb.APIKey))
     {
         // ALWAYS TRY to work with interfaces, because it could go wrong and destroy everything
         try
         {
             return(IEconService.GetTradeOffers(
                        get_sent_offers: BoolToInt(_getSentOffers),
                        get_received_offers: BoolToInt(_getReceivedOffers),
                        get_descriptions: BoolToInt(_getDescription),
                        active_only: BoolToInt(_activeOnly),
                        historical_only: BoolToInt(_historicalOnly),
                        secure: true));
         }
         catch (Exception e)
         {
             m_logger.Warning(e.Message);
             throw;
         }
     }
 }
 public void ExecuteCycle()
 {
     Step();
     Step();
     Logger.Warning($"MICROINSTRUCTION {Convert.ToString((long) MIR.Instance.Value, 16).PadLeft(10, '0')}");
 }
Beispiel #9
0
        /// <summary>
        /// Initialize the cancellationtoken so we can interrupt the method on lost connection
        /// Create a new task with the cancellationtoken
        /// While the task is not cancelled get all badges to farm
        /// If we do not have any badge to farm, remove the playing status so we are shown as online
        ///
        ///     If we have some badges to farm start a new while loop and start to farm this badge
        ///     Check every 5 minutes if we have still some cards left to farm for this badge
        ///     If we do not have any left, leave the while loop
        ///
        /// If we are not comming out from the while loop check every 5 minutes for new badges to farm
        /// If we are comming out fron the while loop we want to check for the next badge to farm, therefore we do not wait 5 minuts
        /// </summary>
        /// <param name="_steamClient"></param>
        public void StartFarmCards(SteamClient _steamClient)
        {
            m_cardFarmCancellationTokenSource = new CancellationTokenSource();

            bool checkForNewGame = false;

            Task.Run(async() =>
            {
                while (!m_cardFarmCancellationTokenSource.Token.IsCancellationRequested)
                {
                    if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false))
                    {
                        continue;
                    }

                    List <GameToFarm> gamesToFarm = await m_steamUserWebAPI.GetBadgesToFarm().ConfigureAwait(false);

                    bool isRunning = (gamesToFarm.Count > 0);

                    if (!isRunning)
                    {
                        m_gamesLibraryHelper.SetGamePlaying(0);
                    }

                    while (isRunning && !m_cardFarmCancellationTokenSource.Token.IsCancellationRequested)
                    {
                        m_gamesLibraryHelper.SetGamePlaying(Convert.ToInt32(gamesToFarm.First().AppID));

                        try
                        {
                            await Task.Delay(TimeSpan.FromMinutes(5), m_cardFarmCancellationTokenSource.Token).ConfigureAwait(false);
                        }
                        catch (Exception)
                        {
                            break;
                        }

                        if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false))
                        {
                            continue;
                        }

                        isRunning = await m_steamUserWebAPI.GetGameCardsRemainingForGame(Convert.ToUInt32(gamesToFarm.First().AppID)).ConfigureAwait(false) > 0;

                        if (!isRunning)
                        {
                            checkForNewGame = true;
                        }
                    }

                    if (!checkForNewGame)
                    {
                        try
                        {
                            await Task.Delay(TimeSpan.FromMinutes(5), m_cardFarmCancellationTokenSource.Token).ConfigureAwait(false);
                        }
                        catch (Exception)
                        {
                            break;
                        }
                    }

                    checkForNewGame = false;
                }

                m_logger.Warning("Cancelled the CardFarmTask.");
                m_cardFarmCancellationTokenSource.Dispose();
            }, m_cardFarmCancellationTokenSource.Token);
        }