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


C# SteamUser.LogOff方法代码示例

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


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

示例1: 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

示例2: Main

        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample7: No username and password specified!" );
                return;
            }

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

            // create our steamclient instance
            steamClient = new SteamClient();
            // create the callback manager which will route callbacks to function calls
            manager = new CallbackManager( steamClient );

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

            // register a few callbacks we're interested in
            // these are registered upon creation to a callback manager, which will then route the callbacks
            // to the functions specified
            manager.Subscribe<SteamClient.ConnectedCallback>( OnConnected );
            manager.Subscribe<SteamClient.DisconnectedCallback>( OnDisconnected );

            manager.Subscribe<SteamUser.LoggedOnCallback>( OnLoggedOn );
            manager.Subscribe<SteamUser.LoggedOffCallback>( OnLoggedOff );

            Console.CancelKeyPress += ( s, e ) =>
            {
                e.Cancel = true;

                Console.WriteLine( "Received {0}, disconnecting...", e.SpecialKey );
                steamUser.LogOff();
            };

            int cellid = 0;

            // if we've previously connected and saved our cellid, load it.
            if ( File.Exists( "cellid.txt" ) )
            {
                if ( !int.TryParse( File.ReadAllText( "cellid.txt"), out cellid ) )
                {
                    Console.WriteLine( "Error parsing cellid from cellid.txt. Continuing with cellid 0." );
                }
            }

            if ( File.Exists( "servers.bin" ) )
            {
                // last time we connected to Steam, we got a list of servers. that list is persisted below.
                // load that list of servers into the server list.
                // this is a very simplistic serialization, you're free to serialize the server list however
                // you like (json, xml, whatever).

                using ( var fs = File.OpenRead( "servers.bin" ) )
                using ( var reader = new BinaryReader( fs ) )
                {
                    while ( fs.Position < fs.Length )
                    {
                        var numAddressBytes = reader.ReadInt32();
                        var addressBytes = reader.ReadBytes( numAddressBytes );
                        var port = reader.ReadInt32();

                        var ipaddress = new IPAddress( addressBytes );
                        var endPoint = new IPEndPoint( ipaddress, port );

                        CMClient.Servers.TryAdd( endPoint );
                    }
                }
            }
            else
            {
                // since we don't have a list of servers saved, load the latest list of Steam servers
                // from the Steam Directory.
                var loadServersTask = SteamDirectory.Initialize( cellid );
                loadServersTask.Wait();

                if ( loadServersTask.IsFaulted )
                {
                    Console.WriteLine( "Error loading server list from directory: {0}", loadServersTask.Exception.Message );
                    return;
                }
            }

            isRunning = true;

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

            // initiate the connection
            steamClient.Connect();

            // create our callback handling loop
            while ( isRunning )
            {
                // in order for the callbacks to get routed, they need to be handled by the manager
                manager.RunWaitCallbacks( TimeSpan.FromSeconds( 1 ) );
            }

            // before we exit, save our current server list to disk.
//.........这里部分代码省略.........
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:101,代码来源:Program.cs

示例3: Main

        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample7: No username and password specified!" );
                return;
            }

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

            // create our steamclient instance
            steamClient = new SteamClient();
            // create the callback manager which will route callbacks to function calls
            manager = new CallbackManager( steamClient );

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

            // register a few callbacks we're interested in
            // these are registered upon creation to a callback manager, which will then route the callbacks
            // to the functions specified
            manager.Subscribe<SteamClient.ConnectedCallback>( OnConnected );
            manager.Subscribe<SteamClient.DisconnectedCallback>( OnDisconnected );

            manager.Subscribe<SteamUser.LoggedOnCallback>( OnLoggedOn );
            manager.Subscribe<SteamUser.LoggedOffCallback>( OnLoggedOff );

            Console.CancelKeyPress += ( s, e ) =>
            {
                e.Cancel = true;

                Console.WriteLine( "Received {0}, disconnecting...", e.SpecialKey );
                steamUser.LogOff();
            };

            var cellid = 0u;

            // if we've previously connected and saved our cellid, load it.
            if ( File.Exists( "cellid.txt" ) )
            {
                if ( !uint.TryParse( File.ReadAllText( "cellid.txt"), out cellid ) )
                {
                    Console.WriteLine( "Error parsing cellid from cellid.txt. Continuing with cellid 0." );
                }
                else
                {
                    Console.WriteLine( $"Using persisted cell ID {cellid}" );
                }
            }

            SteamClient.Servers.CellID = cellid;
            SteamClient.Servers.ServerListProvider = new FileStorageServerListProvider("servers_list.bin");

            isRunning = true;

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

            // initiate the connection
            steamClient.Connect();

            // create our callback handling loop
            while ( isRunning )
            {
                // in order for the callbacks to get routed, they need to be handled by the manager
                manager.RunWaitCallbacks( TimeSpan.FromSeconds( 1 ) );
            }
        }
开发者ID:DoctorMcKay,项目名称:SteamKit,代码行数:69,代码来源:Program.cs


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