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 SteamKit2;
- using System.IO;
- using System.Threading;
- namespace SteamBot
- {
- class Program
- {
- static string user, pass;
- static SteamClient steamClient;
- static CallbackManager manager;
- static SteamUser steamUser;
- static SteamFriends steamFriends;
- static bool isRunning = false;
- static string authCode;
- static void Main(string[] args)
- {
- Console.Title = "SteamBot Console";
- Console.WriteLine("CTRL+C quits the program.");
- Console.Write("Username: ");
- user = Console.ReadLine();
- Console.Write("Password: ");
- pass = Console.ReadLine();
- SteamLogIn();
- }
- static void SteamLogIn()
- {
- steamClient = new SteamClient();
- manager = new CallbackManager(steamClient);
- steamUser = steamClient.GetHandler<SteamUser>();
- steamFriends = steamClient.GetHandler<SteamFriends>();
- new Callback<SteamClient.ConnectedCallback>(OnConnected);
- new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
- new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
- new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
- new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
- new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, manager);
- new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
- isRunning = true;
- Console.WriteLine("Connecting to Steam...");
- steamClient.Connect();
- while (isRunning)
- {
- manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
- }
- Console.ReadKey();
- }
- 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. \nLogging in {0}... \n", user);
- byte[] sentryHash = null;
- if(File.Exists("sentry.bin"))
- {
- byte[] sentryFile = File.ReadAllBytes("sentry.bin");
- sentryHash = CryptoHelper.SHAHash(sentryFile);
- }
- steamUser.LogOn(new SteamUser.LogOnDetails
- {
- Username = user,
- Password = pass,
- AuthCode = authCode,
- TwoFactorCode = twofactor,
- SentryFileHash = sentryHash,
- });
- }
- static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
- {
- if(callback.Result != EResult.AccountLogonDenied)
- {
- Console.WriteLine("Account is SteamGuard protected.");
- Console.Write("Please enter the authentication code sent to the email at {0}: ", callback.EmailDomain);
- authCode = Console.ReadLine();
- return;
- }
- {
- if (callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode)
- {
- Console.WriteLine("Please enter your authentication code\n");
- twofactor = Console.ReadLine();
- return;
- }
- }
- if(callback.Result != EResult.OK)
- {
- Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
- isRunning = false;
- return;
- }
- Console.WriteLine("{0} succesfully logged in.", user);
- }
- static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback, JobID jobID)
- {
- Console.WriteLine("Updating sentry file...");
- byte[] sentryHash = CryptoHelper.SHAHash(callback.Data);
- File.WriteAllBytes("sentry.bin", callback.Data);
- steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
- {
- JobID = jobID,
- FileName = callback.FileName,
- BytesWritten = callback.BytesToWrite,
- FileSize = callback.Data.Length,
- Offset = callback.Offset,
- Result = EResult.OK,
- LastError = 0,
- OneTimePassword = callback.OneTimePassword,
- SentryFileHash = sentryHash,
- });
- Console.WriteLine("Done.");
- }
- static void OnDisconnected(SteamClient.DisconnectedCallback callback)
- {
- Console.WriteLine("\n {0} disconnected from Steam, reconnecting in 5...\n", user);
- Thread.Sleep(TimeSpan.FromSeconds(5));
- steamClient.Connect();
- }
- static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
- {
- Console.WriteLine("Logged off from Steam: {0}", callback.Result);
- }
- static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
- {
- steamFriends.SetPersonaState(EPersonaState.Online);
- }
- 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 "!send":
- break;
- }
- }
- }
- }
- }
- public static string[] seperate(int number,char seperator,string thestring)
- {
- string[] returned = new string[4];
- int i = 0;
- int error = 0;
- int lenght = thestring.Lenght;
- foreach(char c in thestring)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement