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)
- {
- string[] args;
- 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)
- {
- #region send
- case "!send":
- args = seperate(2, ' ', callback.Message);
- Console.WriteLine("!send " + args[1] + args[2] + " command recieved. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
- if(args[0] == "-1")
- {
- steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Command syntax: !send [friend] [message]");
- return;
- }
- for (int i = 0; i < steamFriends.GetFriendCount(); i++)
- {
- SteamID friend = steamFriends.GetFriendByIndex(i);
- if(steamFriends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
- {
- steamFriends.SendChatMessage(friend, EChatEntryType.ChatMsg, args[2]);
- }
- }
- break;
- #endregion
- #region friends
- case "!friends":
- Console.WriteLine("!friends command recieved. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
- for (int i = 0; i < steamFriends.GetFriendCount(); i++)
- {
- SteamID friend = steamFriends.GetFriendByIndex(i);
- steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Friend: " + steamFriends.GetFriendPersonaName(friend) + " State: " + steamFriends.GetFriendPersonaState(friend));
- }
- break;
- #endregion
- }
- }
- }
- }
- }
- public static string[] seperate(int number,char seperator,string thestring)
- {
- string[] returned = new string[4];
- int i = 0;
- int error = 0;
- int lenght = thestring.Length;
- foreach(char c in thestring)
- {
- if(i != number)
- {
- if(error > lenght || number > 5)
- {
- returned[0] = "-1";
- return returned;
- }
- else if(c == seperator)
- {
- returned[i] = thestring.Remove(thestring.IndexOf(c));
- thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
- i++;
- }
- error++;
- if(error > lenght && i != number)
- {
- returned[0] = "-1";
- return returned;
- }
- }
- else
- {
- returned[i] = thestring;
- }
- }
- return returned;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement