LogOn() public method

Logs the client into the Steam3 network. The client should already have been connected at this point. Results are returned in a LoggedOnCallback.
No logon details were provided. Username or password are not set within .
public LogOn ( LogOnDetails details ) : void
details LogOnDetails The details to use for logging on.
return void
Example #1
0
        void OnConnected(SK.SteamClient.ConnectedCallback callback)
        {
            SK.SteamUser.LogOnDetails loginDetails = new SK.SteamUser.LogOnDetails
            {
                Username = Username,
                Password = Password
            };

            if (!string.IsNullOrWhiteSpace(AuthenticationCode))
            {
                loginDetails.AuthCode       = AuthenticationCode;
                loginDetails.TwoFactorCode  = AuthenticationCode;
                loginDetails.SentryFileHash = GetSentryHash();
            }

            steamUser.LogOn(loginDetails);

            Connected?.Invoke(this, null);
        }
Example #2
0
        private void OnConnected(SteamClient.ConnectedCallback obj)
        {
            Console.WriteLine("[Steam] Connected to steam! Logging in as '{0}'...",
                              _config["steam_user"]);

            byte[] sentryHash = null;
            if (File.Exists("sentry.bin"))
            {
                sentryHash = CryptoHelper.SHAHash(
                    File.ReadAllBytes("sentry.bin")
                    );
            }

            _user.LogOn(new SteamUser.LogOnDetails()
            {
                ShouldRememberPassword = true,
                Username       = _config["steam_user"],
                Password       = _config["steam_pass"],
                TwoFactorCode  = _config["steam_mfa"],
                AuthCode       = _config["steam_oauth"],
                SentryFileHash = sentryHash,
            });
        }
Example #3
0
        private void InitAndConnect()
        {
            if (client == null)
            {
                client = new SteamClient();
                DotaGCHandler.Bootstrap(client);
                user = client.GetHandler<SteamUser>();
                friends = client.GetHandler<SteamFriends>();
                dota = client.GetHandler<DotaGCHandler>();
                manager = new CallbackManager(client);

                isRunning = true;
                new Callback<SteamClient.ConnectedCallback>(c =>
                {
                    if (c.Result != EResult.OK)
                    {
                        fsm.FirePriority(Events.Disconnected);
                        isRunning = false;
                        return;
                    }

                    user.LogOn(details);
                }, manager);
                new Callback<SteamClient.DisconnectedCallback>(
                    c => { if (fsm != null) fsm.Fire(Events.Disconnected); }, manager);
                new Callback<SteamUser.LoggedOnCallback>(c =>
                {
                    if (c.Result != EResult.OK)
                    {
                        log.Error("Logon failure, result: " + c.Result);
                        switch (c.Result)
                        {
                            case EResult.AccountLogonDenied:
                                fsm.Fire(Events.LogonFailSteamGuard);
                                return;
                            case EResult.ServiceUnavailable:
                            case EResult.TryAnotherCM:
                                fsm.Fire(Events.LogonFailSteamDown);
                                return;
                        }
                        fsm.Fire(Events.LogonFailBadCreds);
                    }
                    else
                    {
                        fsm.Fire(Events.Connected);
                    }
                }, manager);
                new Callback<DotaGCHandler.UnhandledDotaGCCallback>(
                    c => log.Debug("Unknown GC message: " + c.Message.MsgType), manager);
                new Callback<DotaGCHandler.GCWelcomeCallback>(
                    c => fsm.Fire(Events.DotaGCReady), manager);
                new Callback<SteamFriends.FriendsListCallback>(c => log.Debug(c.FriendList), manager);
                new Callback<DotaGCHandler.PracticeLobbySnapshot>(c =>
                {
                    log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state);

                    fsm.Fire(c.lobby.state == CSODOTALobby.State.RUN
                        ? Events.DotaEnterLobbyRun
                        : Events.DotaEnterLobbyUI);

                    switch (c.lobby.state)
                    {
                        case CSODOTALobby.State.UI:
                            fsm.FirePriority(Events.DotaEnterLobbyUI);
                            break;
                        case CSODOTALobby.State.RUN:
                            fsm.FirePriority(Events.DotaEnterLobbyRun);
                            break;
                    }
                    LobbyUpdate?.Invoke(c.lobby);
                }, manager);
                new Callback<DotaGCHandler.PingRequest>(c =>
                {
                    log.Debug("GC Sent a ping request. Sending pong!");
                    dota.Pong();
                }, manager);
                new Callback<DotaGCHandler.Popup>(
                    c => { log.DebugFormat("Received message (popup) from GC: {0}", c.result.id); }, manager);
                new Callback<DotaGCHandler.ConnectionStatus>(
                    c => log.DebugFormat("GC Connection Status: {0}", JObject.FromObject(c.result)), manager);
                new Callback<DotaGCHandler.PracticeLobbySnapshot>(c =>
                {
                    log.DebugFormat("Lobby snapshot received with state: {0}", c.lobby.state);
                    if (c.lobby != null)
                    {
                        switch (c.lobby.state)
                        {
                            case CSODOTALobby.State.UI:
                                fsm.FirePriority(Events.DotaEnterLobbyUI);
                                break;
                            case CSODOTALobby.State.RUN:
                                fsm.FirePriority(Events.DotaEnterLobbyRun);
                                break;
                        }
                    }
                    LobbyUpdate?.Invoke(c.lobby);
                }, manager);
            }
            client.Connect();
            procThread = new Thread(SteamThread);
            procThread.Start(this);
        }
Example #4
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample1: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new SteamClient();

            // get the steamuser handler, which is used for logging on after successfully connecting
            steamUser = steamClient.GetHandler<SteamUser>();
            
            isRunning = true;

            Console.WriteLine( "Connecting to Steam..." );

            // initiate the connection
            steamClient.Connect();

            // create our callback handling loop
            while ( isRunning )
            {
                // wait for a callback to be posted
                var callback = steamClient.WaitForCallback( true );

                // handle the callback
                // the Handle function will only call the passed in handler
                // if the callback type matches the generic type
                callback.Handle<SteamClient.ConnectedCallback>( c =>
                {
                    if ( c.Result != EResult.OK )
                    {
                        Console.WriteLine( "Unable to connect to Steam: {0}", c.Result );

                        isRunning = false;
                        return;
                    }

                    Console.WriteLine( "Connected to Steam! Logging in '{0}'...", user );

                    steamUser.LogOn( new SteamUser.LogOnDetails
                    {
                        Username = user,
                        Password = pass,
                    } );
                } );

                callback.Handle<SteamClient.DisconnectedCallback>( c =>
                {
                    Console.WriteLine( "Disconnected from Steam" );

                    isRunning = false;
                } );

                callback.Handle<SteamUser.LoggedOnCallback>( c =>
                {
                    if ( c.Result != EResult.OK )
                    {
                        if ( c.Result == EResult.AccountLogonDenied )
                        {
                            // if we recieve AccountLogonDenied or one of it's flavors (AccountLogonDeniedNoMailSent, etc)
                            // then the account we're logging into is SteamGuard protected
                            // see sample 6 for how SteamGuard can be handled

                            Console.WriteLine( "Unable to logon to Steam: This account is SteamGuard protected." );

                            isRunning = false;
                            return;
                        }

                        Console.WriteLine( "Unable to logon to Steam: {0} / {1}", c.Result, c.ExtendedResult );

                        isRunning = false;
                        return;
                    }

                    Console.WriteLine( "Successfully logged on!" );

                    // at this point, we'd be able to perform actions on Steam

                    // for this sample we'll just log off
                    steamUser.LogOff();
                } );

                callback.Handle<SteamUser.LoggedOffCallback>( c =>
                {
                    Console.WriteLine( "Logged off of Steam: {0}", c.Result );
                } );
            }
        }