当前位置: 首页>>代码示例>>C#>>正文


C# SteamUser.LogOn方法代码示例

本文整理汇总了C#中SteamKit2.SteamUser.LogOn方法的典型用法代码示例。如果您正苦于以下问题:C# SteamUser.LogOn方法的具体用法?C# SteamUser.LogOn怎么用?C# SteamUser.LogOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SteamKit2.SteamUser的用法示例。


在下文中一共展示了SteamUser.LogOn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitAndConnect

        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);
//.........这里部分代码省略.........
开发者ID:mar5,项目名称:Dota2LobbyDump,代码行数:101,代码来源:Bot.cs

示例2: Main

        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 );
                } );
            }
        }
开发者ID:Badca52,项目名称:SteamKit,代码行数:96,代码来源:Program.cs


注:本文中的SteamKit2.SteamUser.LogOn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。