Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Security.Cryptography;
- using System.Threading;
- using SteamKit2;
- namespace Steambotlogin
- {
- class Program
- {
- static SteamClient steamClient;
- static CallbackManager manager;
- static SteamUser steamUser;
- static SteamFriends steamFriends;
- static bool isRunning;
- static string user, pass;
- static string authCode, twoFactorAuth;
- static void Main(string[] args)
- {
- SteamDirectory.Initialize().Wait();
- /*Console.Write("Please enter your username: ");
- user = Console.ReadLine();
- Console.Write("Please enter your password: ");
- pass = Console.ReadLine();
- */
- user = "";
- pass = "";
- steamClient = new SteamClient();
- manager = new CallbackManager(steamClient);
- steamUser = steamClient.GetHandler<SteamUser>();
- steamFriends = steamClient.GetHandler<SteamFriends>();
- manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
- manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
- manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
- manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
- manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
- manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
- manager.Subscribe<SteamFriends.FriendMsgCallback>(OnChatMessage);
- isRunning = true;
- Console.WriteLine("Connecting to Steam...");
- SteamDirectory.Initialize().Wait();
- steamClient.Connect();
- while (isRunning)
- {
- manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
- }
- }
- static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
- {
- steamFriends.SetPersonaState(EPersonaState.Online);
- }
- static void OnConnected(SteamClient.ConnectedCallback callback)
- {
- if (callback.Result != EResult.OK)
- {
- Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
- isRunning = false;
- return;
- }
- Console.WriteLine("Connected to Steam! Logging in '{0}'...", user);
- byte[] sentryHash = null;
- if (File.Exists("sentry.bin"))
- {
- // if we have a saved sentry file, read and sha-1 hash it
- byte[] sentryFile = File.ReadAllBytes("sentry.bin");
- sentryHash = CryptoHelper.SHAHash(sentryFile);
- }
- steamUser.LogOn(new SteamUser.LogOnDetails
- {
- Username = user,
- Password = pass,
- // in this sample, we pass in an additional authcode
- // this value will be null (which is the default) for our first logon attempt
- AuthCode = authCode,
- // if the account is using 2-factor auth, we'll provide the two factor code instead
- // this will also be null on our first logon attempt
- TwoFactorCode = twoFactorAuth,
- // our subsequent logons use the hash of the sentry file as proof of ownership of the file
- // this will also be null for our first (no authcode) and second (authcode only) logon attempts
- SentryFileHash = sentryHash,
- });
- }
- static void OnDisconnected(SteamClient.DisconnectedCallback callback)
- {
- // after recieving an AccountLogonDenied, we'll be disconnected from steam
- // so after we read an authcode from the user, we need to reconnect to begin the logon flow again
- Console.WriteLine("Disconnected from Steam, reconnecting in 5...");
- Thread.Sleep(TimeSpan.FromSeconds(5));
- steamClient.Connect();
- }
- static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
- {
- bool isSteamGuard = callback.Result == EResult.AccountLogonDenied;
- bool is2FA = callback.Result == EResult.AccountLoginDeniedNeedTwoFactor;
- if (isSteamGuard || is2FA)
- {
- Console.WriteLine("This account is SteamGuard protected!");
- if (is2FA)
- {
- Console.Write("Please enter your 2 factor auth code from your authenticator app: ");
- twoFactorAuth = Console.ReadLine();
- }
- else
- {
- Console.Write("Please enter the auth code sent to the email at {0}: ", callback.EmailDomain);
- authCode = Console.ReadLine();
- }
- return;
- }
- if (callback.Result != EResult.OK)
- {
- Console.WriteLine("Unable to logon to Steam: {0} / {1}", callback.Result, callback.ExtendedResult);
- isRunning = false;
- return;
- }
- Console.WriteLine("Successfully logged on!");
- // at this point, we'd be able to perform actions on Steam
- }
- static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
- {
- Console.WriteLine("Logged off of Steam: {0}", callback.Result);
- }
- static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
- {
- Console.WriteLine("Updating sentryfile...");
- // write out our sentry file
- // ideally we'd want to write to the filename specified in the callback
- // but then this sample would require more code to find the correct sentry file to read during logon
- // for the sake of simplicity, we'll just use "sentry.bin"
- int fileSize;
- byte[] sentryHash;
- using (var fs = File.Open("sentry.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite))
- {
- fs.Seek(callback.Offset, SeekOrigin.Begin);
- fs.Write(callback.Data, 0, callback.BytesToWrite);
- fileSize = (int)fs.Length;
- fs.Seek(0, SeekOrigin.Begin);
- using (var sha = new SHA1CryptoServiceProvider())
- {
- sentryHash = sha.ComputeHash(fs);
- }
- }
- // inform the steam servers that we're accepting this sentry file
- steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
- {
- JobID = callback.JobID,
- FileName = callback.FileName,
- BytesWritten = callback.BytesToWrite,
- FileSize = fileSize,
- Offset = callback.Offset,
- Result = EResult.OK,
- LastError = 0,
- OneTimePassword = callback.OneTimePassword,
- SentryFileHash = sentryHash,
- });
- Console.WriteLine("Done!");
- }
- static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
- {
- if (callback.EntryType == EChatEntryType.ChatMsg)
- {
- if(callback.Message.Length > 1)
- {
- if(callback.Message.Remove(1) == "!")
- {
- string command = callback.Message;
- if(callback.Message.Contains(" "))
- {
- command = callback.Message.Remove(callback.Message.IndexOf(" "))
- }
- switch(command)
- {
- case command = "!help"
- break;
- }
- }
- }
- steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Hello, this is a bot");
- }
- }
- public static string[] seperate(int number, char seperator, string thestring)
- {
- string[] returned = new string[4]
- int i = 0;
- int error = 0;
- int length = thestring.length;
- foreach
- if(int != number)
- {
- if(error > lenghth || number > 5)
- {
- returned[0] = "-1";
- return returned;
- }
- else if(char == seperator)
- {
- returned[i] = thestring.Remove(thestring.IndexOf(c));
- thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement