示例#1
0
        public void HandleCallback(CallbackMsg msg)
        {
            if (msg.IsType <SteamFriends.PersonaStateCallback>())
            {
                var perState = (SteamFriends.PersonaStateCallback)msg;

                if (perState.FriendID == selfControl.Friend.SteamID)
                {
                    selfControl.UpdateFriend(selfControl.Friend);

                    suppressStateMsg            = true;
                    stateComboBox.SelectedIndex = GetIndexFromState(perState.State);
                    suppressStateMsg            = false;

                    return;
                }

                nextSort = DateTime.Now + TimeSpan.FromSeconds(0.1);
                sortTimer.Start();
            }

            if (msg.IsType <SteamUser.LoggedOffCallback>())
            {
                var callback = (SteamUser.LoggedOffCallback)msg;

                Util.MsgBox(this, string.Format("Logged off from Steam3: {0}", callback.Result));

                this.Relog = true;
                this.Close();

                return;
            }

            if (msg.IsType <SteamFriends.FriendsListCallback>())
            {
                selfControl.UpdateFriend(new Friend(Steam3.SteamUser.SteamID));
                this.UpdateFriends();
            }

            if (msg.IsType <SteamUser.LoginKeyCallback>())
            {
                Steam3.SteamFriends.SetPersonaState(EPersonaState.Online);
                this.Enabled = true;
            }

            if (msg.IsType <SteamUser.LoggedOnCallback>())
            {
                var logOnResp = (SteamUser.LoggedOnCallback)msg;

                if (logOnResp.Result == EResult.AccountLogonDenied)
                {
                    expectDisconnect = true;

                    SteamGuardDialog sgDialog = new SteamGuardDialog();

                    if (sgDialog.ShowDialog(this) != DialogResult.OK)
                    {
                        this.Relog = true;
                        this.Close();

                        return;
                    }

                    Steam3.AuthCode = sgDialog.AuthCode;

                    // if we got this logon response, we got disconnected, so lets reconnect
                    try
                    {
                        Steam3.Connect();
                    }
                    catch (Steam3Exception ex)
                    {
                        Util.MsgBox(this, string.Format("Unable to connect to Steam3: {0}", ex.Message));

                        this.Relog = true;
                        this.Close();

                        return;
                    }
                }
                else if (logOnResp.Result != EResult.OK)
                {
                    Util.MsgBox(this, string.Format("Unable to login to Steam3. Result code: {0}", logOnResp.Result));

                    this.Relog = true;
                    this.Close();

                    return;
                }
            }

            if (msg.IsType <SteamFriends.FriendAddedCallback>())
            {
                var friendAdded = (SteamFriends.FriendAddedCallback)msg;

                if (friendAdded.Result != EResult.OK)
                {
                    Util.MsgBox(this, "Unable to add friend! Result: " + friendAdded.Result);
                }
            }

            msg.Handle <SteamClient.DisconnectedCallback>((callback) =>
            {
                // if we expected this disconnection (cause of steamguard), we do nothing
                if (expectDisconnect)
                {
                    expectDisconnect = false;
                    return;
                }

                Util.MsgBox(this, "Disconnected from Steam3!");

                this.Relog = true;
                this.Close();

                return;
            });
        }
示例#2
0
        public void HandleCallback( CallbackMsg msg )
        {
            if ( msg.IsType<SteamFriends.PersonaStateCallback>() )
            {
                var perState = ( SteamFriends.PersonaStateCallback )msg;

                if ( perState.FriendID == selfControl.Friend.SteamID )
                {
                    selfControl.UpdateFriend( selfControl.Friend );

                    suppressStateMsg = true;
                    stateComboBox.SelectedIndex = GetIndexFromState( perState.State );
                    suppressStateMsg = false;

                    return;
                }

                nextSort = DateTime.Now + TimeSpan.FromSeconds( 0.1 );
                sortTimer.Start();
            }

            if ( msg.IsType<SteamUser.LoggedOffCallback>() )
            {
                var callback = ( SteamUser.LoggedOffCallback )msg;

                Util.MsgBox( this, string.Format( "Logged off from Steam3: {0}", callback.Result ) );

                this.Relog = true;
                this.Close();

                return;
            }

            if ( msg.IsType<SteamFriends.FriendsListCallback>() )
            {
                selfControl.UpdateFriend( new Friend( Steam3.SteamUser.SteamID ) );
                this.UpdateFriends();
            }

            if ( msg.IsType<SteamUser.LoginKeyCallback>() )
            {
                Steam3.SteamFriends.SetPersonaState( EPersonaState.Online );
                this.Enabled = true;
            }

            if ( msg.IsType<SteamUser.LoggedOnCallback>() )
            {
                var logOnResp = ( SteamUser.LoggedOnCallback )msg;

                if ( logOnResp.Result == EResult.AccountLogonDenied )
                {
                    expectDisconnect = true;

                    SteamGuardDialog sgDialog = new SteamGuardDialog();

                    if ( sgDialog.ShowDialog( this ) != DialogResult.OK )
                    {
                        this.Relog = true;
                        this.Close();

                        return;
                    }

                    Steam3.AuthCode = sgDialog.AuthCode;

                    // if we got this logon response, we got disconnected, so lets reconnect
                    try
                    {
                        Steam3.Connect();
                    }
                    catch ( Steam3Exception ex )
                    {
                        Util.MsgBox( this, string.Format( "Unable to connect to Steam3: {0}", ex.Message ) );

                        this.Relog = true;
                        this.Close();

                        return;
                    }
                }
                else if ( logOnResp.Result != EResult.OK )
                {
                    Util.MsgBox( this, string.Format( "Unable to login to Steam3. Result code: {0}", logOnResp.Result ) );

                    this.Relog = true;
                    this.Close();

                    return;
                }
            }

            if ( msg.IsType<SteamFriends.FriendAddedCallback>() )
            {
                var friendAdded = ( SteamFriends.FriendAddedCallback )msg;

                if ( friendAdded.Result != EResult.OK )
                {
                    Util.MsgBox( this, "Unable to add friend! Result: " + friendAdded.Result );
                }
            }

            msg.Handle<SteamClient.DisconnectedCallback>( ( callback ) =>
            {
                // if we expected this disconnection (cause of steamguard), we do nothing
                if ( expectDisconnect )
                {
                    expectDisconnect = false;
                    return;
                }

                Util.MsgBox( this, "Disconnected from Steam3!" );

                this.Relog = true;
                this.Close();

                return;
            } );
        }