Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using SteamKit2;
  7. using System.IO;
  8. using System.Threading;
  9.  
  10. namespace SteamBot
  11. {
  12. class Program
  13. {
  14. static string user, pass;
  15.  
  16. static SteamClient steamClient;
  17. static CallbackManager manager;
  18. static SteamUser steamUser;
  19. static SteamFriends steamFriends;
  20.  
  21. static bool isRunning = false;
  22.  
  23. static string authCode;
  24.  
  25. static void Main(string[] args)
  26. {
  27. Console.Title = "SteamBot Console";
  28. Console.WriteLine("CTRL+C quits the program.");
  29.  
  30. Console.Write("Username: ");
  31. user = Console.ReadLine();
  32.  
  33. Console.Write("Password: ");
  34. pass = Console.ReadLine();
  35.  
  36. SteamLogIn();
  37. }
  38.  
  39. static void SteamLogIn()
  40. {
  41. steamClient = new SteamClient();
  42.  
  43. manager = new CallbackManager(steamClient);
  44.  
  45. steamUser = steamClient.GetHandler<SteamUser>();
  46.  
  47. steamFriends = steamClient.GetHandler<SteamFriends>();
  48.  
  49. new Callback<SteamClient.ConnectedCallback>(OnConnected);
  50. new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
  51.  
  52. new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
  53. new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
  54.  
  55. new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
  56. new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, manager);
  57.  
  58. new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
  59.  
  60. isRunning = true;
  61.  
  62. Console.WriteLine("Connecting to Steam...");
  63.  
  64. steamClient.Connect();
  65.  
  66.  
  67. while (isRunning)
  68. {
  69. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  70. }
  71. Console.ReadKey();
  72. }
  73.  
  74. static void OnConnected(SteamClient.ConnectedCallback callback)
  75. {
  76. if (callback.Result != EResult.OK)
  77. {
  78. Console.WriteLine("Unable to connect to steam: {0}", callback.Result);
  79.  
  80. isRunning = false;
  81. return;
  82. }
  83.  
  84. Console.WriteLine("Connected to Steam. \nLogging in {0}... \n", user);
  85.  
  86. byte[] sentryHash = null;
  87.  
  88. if(File.Exists("sentry.bin"))
  89. {
  90. byte[] sentryFile = File.ReadAllBytes("sentry.bin");
  91.  
  92. sentryHash = CryptoHelper.SHAHash(sentryFile);
  93. }
  94.  
  95. steamUser.LogOn(new SteamUser.LogOnDetails
  96. {
  97. Username = user,
  98. Password = pass,
  99.  
  100. AuthCode = authCode,
  101.  
  102. TwoFactorCode = twofactor,
  103.  
  104. SentryFileHash = sentryHash,
  105. });
  106. }
  107.  
  108. static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  109. {
  110. if(callback.Result != EResult.AccountLogonDenied)
  111. {
  112. Console.WriteLine("Account is SteamGuard protected.");
  113.  
  114. Console.Write("Please enter the authentication code sent to the email at {0}: ", callback.EmailDomain);
  115.  
  116. authCode = Console.ReadLine();
  117.  
  118. return;
  119. }
  120.  
  121. {
  122. if (callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode)
  123. {
  124. Console.WriteLine("Please enter your authentication code\n");
  125.  
  126. twofactor = Console.ReadLine();
  127.  
  128. return;
  129. }
  130. }
  131.  
  132. if(callback.Result != EResult.OK)
  133. {
  134. Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
  135. isRunning = false;
  136. return;
  137. }
  138. Console.WriteLine("{0} succesfully logged in.", user);
  139.  
  140. }
  141.  
  142. static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback, JobID jobID)
  143. {
  144. Console.WriteLine("Updating sentry file...");
  145.  
  146. byte[] sentryHash = CryptoHelper.SHAHash(callback.Data);
  147.  
  148. File.WriteAllBytes("sentry.bin", callback.Data);
  149.  
  150. steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  151. {
  152. JobID = jobID,
  153. FileName = callback.FileName,
  154. BytesWritten = callback.BytesToWrite,
  155. FileSize = callback.Data.Length,
  156. Offset = callback.Offset,
  157. Result = EResult.OK,
  158. LastError = 0,
  159. OneTimePassword = callback.OneTimePassword,
  160. SentryFileHash = sentryHash,
  161. });
  162.  
  163. Console.WriteLine("Done.");
  164. }
  165.  
  166. static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  167. {
  168. Console.WriteLine("\n {0} disconnected from Steam, reconnecting in 5...\n", user);
  169.  
  170. Thread.Sleep(TimeSpan.FromSeconds(5));
  171.  
  172. steamClient.Connect();
  173. }
  174.  
  175. static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  176. {
  177. Console.WriteLine("Logged off from Steam: {0}", callback.Result);
  178. }
  179.  
  180. static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  181. {
  182. steamFriends.SetPersonaState(EPersonaState.Online);
  183.  
  184. }
  185.  
  186. static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  187. {
  188. if(callback.EntryType == EChatEntryType.ChatMsg)
  189. {
  190. if (callback.Message.Length > 1)
  191. {
  192. if(callback.Message.Remove(1) == "!")
  193. {
  194. string command = callback.Message;
  195. if(callback.Message.Contains(" "))
  196. {
  197. command = callback.Message.Remove(callback.Message.IndexOf(' '));
  198. }
  199.  
  200. switch(command)
  201. {
  202. case "!send":
  203. break;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. public static string[] seperate(int number,char seperator,string thestring)
  210. {
  211. string[] returned = new string[4];
  212.  
  213. int i = 0;
  214.  
  215. int error = 0;
  216.  
  217. int lenght = thestring.Lenght;
  218.  
  219. foreach(char c in thestring)
  220. {
  221.  
  222. }
  223. }
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement