Exemple #1
0
        public Steam3Session(SteamUser.LogOnDetails details)
        {
            this.logonDetails = details;

            this.authenticatedUser          = details.Username != null;
            this.credentials                = new Credentials();
            this.bConnected                 = false;
            this.bConnecting                = false;
            this.bAborted                   = false;
            this.bExpectingDisconnectRemote = false;
            this.bDidDisconnect             = false;
            this.bDidReceiveLoginKey        = false;
            this.seq = 0;

            this.AppTickets       = new Dictionary <uint, byte[]>();
            this.AppTokens        = new Dictionary <uint, ulong>();
            this.PackageTokens    = new Dictionary <uint, ulong>();
            this.DepotKeys        = new Dictionary <uint, byte[]>();
            this.CDNAuthTokens    = new ConcurrentDictionary <string, TaskCompletionSource <SteamApps.CDNAuthTokenCallback> >();
            this.AppInfo          = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
            this.PackageInfo      = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
            this.AppBetaPasswords = new Dictionary <string, byte[]>();

            this.steamClient = new SteamClient();

            this.steamUser  = this.steamClient.GetHandler <SteamUser>();
            this.steamApps  = this.steamClient.GetHandler <SteamApps>();
            this.steamCloud = this.steamClient.GetHandler <SteamCloud>();
            var steamUnifiedMessages = this.steamClient.GetHandler <SteamUnifiedMessages>();

            this.steamPublishedFile = steamUnifiedMessages.CreateService <IPublishedFile>();

            this.callbacks = new CallbackManager(this.steamClient);

            this.callbacks.Subscribe <SteamClient.ConnectedCallback>(ConnectedCallback);
            this.callbacks.Subscribe <SteamClient.DisconnectedCallback>(DisconnectedCallback);
            this.callbacks.Subscribe <SteamUser.LoggedOnCallback>(LogOnCallback);
            this.callbacks.Subscribe <SteamUser.SessionTokenCallback>(SessionTokenCallback);
            this.callbacks.Subscribe <SteamApps.LicenseListCallback>(LicenseListCallback);
            this.callbacks.Subscribe <SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback);
            this.callbacks.Subscribe <SteamUser.LoginKeyCallback>(LoginKeyCallback);

            Console.Write("Connecting to Steam3...");

            if (authenticatedUser)
            {
                FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username));
                if (AccountSettingsStore.Instance.SentryData != null && AccountSettingsStore.Instance.SentryData.ContainsKey(logonDetails.Username))
                {
                    logonDetails.SentryFileHash = Util.SHAHash(AccountSettingsStore.Instance.SentryData[logonDetails.Username]);
                }
                else if (fi.Exists && fi.Length > 0)
                {
                    var sentryData = File.ReadAllBytes(fi.FullName);
                    logonDetails.SentryFileHash = Util.SHAHash(sentryData);
                    AccountSettingsStore.Instance.SentryData[logonDetails.Username] = sentryData;
                    AccountSettingsStore.Save();
                }
            }

            Connect();
        }
Exemple #2
0
        private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn)
        {
            bool isSteamGuard = loggedOn.Result == EResult.AccountLogonDenied;
            bool is2FA        = loggedOn.Result == EResult.AccountLoginDeniedNeedTwoFactor;
            bool isLoginKey   = ContentDownloader.Config.RememberPassword && logonDetails.LoginKey != null && loggedOn.Result == EResult.InvalidPassword;

            int screenWidth  = Screen.PrimaryScreen.WorkingArea.Width / 2;
            int screenHeight = Screen.PrimaryScreen.WorkingArea.Height / 2;

            if (isSteamGuard || is2FA || isLoginKey)
            {
                bExpectingDisconnectRemote = true;
                Abort(false);

                if (!isLoginKey)
                {
                    Console.WriteLine("This account is protected by Steam Guard.");
                }

                if (is2FA)
                {
                    Console.Write("Please enter your 2 factor auth code from your authenticator app: ");
                    logonDetails.TwoFactorCode = Interaction.InputBox("Please enter your 2 factor auth code from your authenticator app: ",
                                                                      "Provide 2 Auth",
                                                                      "",
                                                                      screenWidth,
                                                                      screenHeight);
                }
                else if (isLoginKey)
                {
                    AccountSettingsStore.Instance.LoginKeys.Remove(logonDetails.Username);
                    AccountSettingsStore.Save();

                    logonDetails.LoginKey = null;

                    if (ContentDownloader.Config.SuppliedPassword != null)
                    {
                        Console.WriteLine("Login key was expired. Connecting with supplied password.");
                        logonDetails.Password = ContentDownloader.Config.SuppliedPassword;
                    }
                    else
                    {
                        Console.Write("Login key was expired. Please enter your password: "******"Please enter the authentication code sent to your email address: ");
                    logonDetails.AuthCode = Interaction.InputBox("Please enter the authentication code sent to your email address: ",
                                                                 "Provide 2 Auth",
                                                                 "",
                                                                 screenWidth,
                                                                 screenHeight);
                }

                Console.Write("Retrying Steam3 connection...");
                Connect();

                return;
            }
            else if (loggedOn.Result == EResult.ServiceUnavailable)
            {
                Console.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result);
                Abort(false);

                return;
            }
            else if (loggedOn.Result != EResult.OK)
            {
                Console.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result);
                Abort();

                return;
            }

            Console.WriteLine(" Done!");

            this.seq++;
            credentials.LoggedOn = true;

            if (ContentDownloader.Config.CellID == 0)
            {
                Console.WriteLine("Using Steam3 suggested CellID: " + loggedOn.CellID);
                ContentDownloader.Config.CellID = ( int )loggedOn.CellID;
            }
        }