Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.10 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Threading;
  5. using SteamKit2.Discovery;
  6.  
  7. using SteamKit2;
  8. using SteamKit2.Internal; // brings in our protobuf client messages
  9. using SteamKit2.GC; // brings in the GC related classes
  10. using SteamKit2.GC.Artifact.Internal;
  11. using System.Text;
  12.  
  13. namespace ShowPlayers
  14. {
  15.     class Program
  16.     {
  17.     static SteamClient steamClient;
  18.     static CallbackManager manager;
  19.  
  20.     static SteamUser steamUser;
  21.  
  22.     static bool isRunning;
  23.  
  24.     static string user, pass;
  25.     static string authCode, twoFactorAuth;
  26.      const int APPID = 346110;
  27.     static SteamGameCoordinator gameCoordinator;
  28.  
  29.  
  30.         static void Main(string[] args)
  31.     {
  32.  
  33.         user = "...";
  34.         pass = "...";
  35.         steamClient = new SteamClient();
  36.         manager = new CallbackManager(steamClient);
  37.        
  38.         steamUser = steamClient.GetHandler<SteamUser>();
  39.         gameCoordinator = steamClient.GetHandler<SteamGameCoordinator>();
  40.  
  41.  
  42.         manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
  43.         manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
  44.  
  45.         manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
  46.         manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
  47.         manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
  48.         manager.Subscribe<SteamFriends.PersonaStateCallback>(OnPersona);
  49.        isRunning = true;
  50.  
  51.         Console.WriteLine("Connecting to Steam...");
  52.  
  53.         steamClient.Connect();
  54.         while (isRunning)
  55.         {
  56.             manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  57.         }
  58.     }
  59.         static void OnPersona(SteamFriends.PersonaStateCallback callback)
  60.         {
  61.  
  62.             Console.WriteLine("Connected to Steam! Logging in '{0}'...", callback);
  63.  
  64.         }
  65.  
  66.  
  67.  
  68.         static void OnConnected(SteamClient.ConnectedCallback callback)
  69.     {
  70.         Console.WriteLine("Connected to Steam! Logging in '{0}'...", user);
  71.  
  72.         byte[] sentryHash = null;
  73.         if (File.Exists("sentry.bin"))
  74.         {
  75.             // if we have a saved sentry file, read and sha-1 hash it
  76.             byte[] sentryFile = File.ReadAllBytes("sentry.bin");
  77.             sentryHash = CryptoHelper.SHAHash(sentryFile);
  78.         }
  79.  
  80.         steamUser.LogOn(new SteamUser.LogOnDetails
  81.         {
  82.             Username = user,
  83.             Password = pass,
  84.  
  85.             // in this sample, we pass in an additional authcode
  86.             // this value will be null (which is the default) for our first logon attempt
  87.             AuthCode = authCode,
  88.  
  89.             // if the account is using 2-factor auth, we'll provide the two factor code instead
  90.             // this will also be null on our first logon attempt
  91.             TwoFactorCode = twoFactorAuth,
  92.  
  93.             // our subsequent logons use the hash of the sentry file as proof of ownership of the file
  94.             // this will also be null for our first (no authcode) and second (authcode only) logon attempts
  95.             SentryFileHash = sentryHash,
  96.         });
  97.  
  98.             var playGame = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayedWithDataBlob);
  99.             playGame.Body.client_os_type = 16;
  100.  
  101.             playGame.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed
  102.             {
  103.                 steam_id_gs = 90127163137042442,
  104.                 game_id = new GameID(APPID), // or game_id = APPID,
  105.                 game_ip_address = 621444212,
  106.                 game_port = 7781,
  107.                 game_extra_info = "",
  108.                 process_id = 18964,
  109.                 game_flags = 0,
  110.                 owner_id = 400168753,
  111.             });
  112.  
  113.             // send it off
  114.             // notice here we're sending this message directly using the SteamClient
  115.          // steamClient.Send(playGame);
  116.  
  117.  
  118.         }
  119.  
  120.     static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  121.     {
  122.         // after recieving an AccountLogonDenied, we'll be disconnected from steam
  123.         // so after we read an authcode from the user, we need to reconnect to begin the logon flow again
  124.  
  125.         Console.WriteLine("Disconnected from Steam, reconnecting in 5...");
  126.  
  127.         Thread.Sleep(TimeSpan.FromSeconds(5));
  128.  
  129.         steamClient.Connect();
  130.     }
  131.  
  132.     static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  133.     {
  134.         bool isSteamGuard = callback.Result == EResult.AccountLogonDenied;
  135.         bool is2FA = callback.Result == EResult.AccountLoginDeniedNeedTwoFactor;
  136.  
  137.         if (isSteamGuard || is2FA)
  138.         {
  139.             Console.WriteLine("This account is SteamGuard protected!");
  140.  
  141.             if (is2FA)
  142.             {
  143.                 Console.Write("Please enter your 2 factor auth code from your authenticator app: ");
  144.                 twoFactorAuth = Console.ReadLine();
  145.             }
  146.             else
  147.             {
  148.                 Console.Write("Please enter the auth code sent to the email at {0}: ", callback.EmailDomain);
  149.                 authCode = Console.ReadLine();
  150.             }
  151.  
  152.             return;
  153.         }
  154.  
  155.         if (callback.Result != EResult.OK)
  156.         {
  157.             Console.WriteLine("Unable to logon to Steam: {0} / {1}", callback.Result, callback.ExtendedResult);
  158.  
  159.             isRunning = false;
  160.             return;
  161.         }
  162.  
  163.         Console.WriteLine("Successfully logged on!");
  164.         File.WriteAllText("cellid.txt", callback.CellID.ToString());
  165.  
  166.         }
  167.  
  168.     static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  169.     {
  170.         Console.WriteLine("Logged off of Steam: {0}", callback.Result);
  171.     }
  172.  
  173.     static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
  174.     {
  175.         Console.WriteLine("Updating sentryfile...");
  176.  
  177.         // write out our sentry file
  178.         // ideally we'd want to write to the filename specified in the callback
  179.         // but then this sample would require more code to find the correct sentry file to read during logon
  180.         // for the sake of simplicity, we'll just use "sentry.bin"
  181.  
  182.         int fileSize;
  183.         byte[] sentryHash;
  184.         using (var fs = File.Open("sentry.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite))
  185.         {
  186.             fs.Seek(callback.Offset, SeekOrigin.Begin);
  187.             fs.Write(callback.Data, 0, callback.BytesToWrite);
  188.             fileSize = (int)fs.Length;
  189.  
  190.             fs.Seek(0, SeekOrigin.Begin);
  191.             using (var sha = SHA1.Create())
  192.             {
  193.                 sentryHash = sha.ComputeHash(fs);
  194.             }
  195.         }
  196.  
  197.         // inform the steam servers that we're accepting this sentry file
  198.         steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  199.         {
  200.             JobID = callback.JobID,
  201.  
  202.             FileName = callback.FileName,
  203.  
  204.             BytesWritten = callback.BytesToWrite,
  205.             FileSize = fileSize,
  206.             Offset = callback.Offset,
  207.  
  208.             Result = EResult.OK,
  209.             LastError = 0,
  210.  
  211.             OneTimePassword = callback.OneTimePassword,
  212.  
  213.             SentryFileHash = sentryHash,
  214.         });
  215.  
  216.         Console.WriteLine("Done!");
  217.     }
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement