Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 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 System.IO;
  7. using System.Security.Cryptography;
  8. using System.Threading;
  9. using SteamKit2;
  10.  
  11. namespace Steambotlogin
  12. {
  13. class Program
  14. {
  15. static SteamClient steamClient;
  16. static CallbackManager manager;
  17.  
  18. static SteamUser steamUser;
  19. static SteamFriends steamFriends;
  20.  
  21. static bool isRunning;
  22.  
  23. static string user, pass;
  24. static string authCode, twoFactorAuth;
  25.  
  26.  
  27.  
  28. static void Main(string[] args)
  29. {
  30. SteamDirectory.Initialize().Wait();
  31. /*Console.Write("Please enter your username: ");
  32. user = Console.ReadLine();
  33.  
  34. Console.Write("Please enter your password: ");
  35. pass = Console.ReadLine();
  36. */
  37. user = "";
  38. pass = "";
  39.  
  40. steamClient = new SteamClient();
  41.  
  42. manager = new CallbackManager(steamClient);
  43.  
  44. steamUser = steamClient.GetHandler<SteamUser>();
  45.  
  46. steamFriends = steamClient.GetHandler<SteamFriends>();
  47.  
  48. manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
  49. manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
  50.  
  51. manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
  52. manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
  53. manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
  54. manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
  55. manager.Subscribe<SteamFriends.FriendMsgCallback>(OnChatMessage);
  56.  
  57. isRunning = true;
  58.  
  59. Console.WriteLine("Connecting to Steam...");
  60.  
  61. SteamDirectory.Initialize().Wait();
  62. steamClient.Connect();
  63.  
  64. while (isRunning)
  65. {
  66. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  67. }
  68. }
  69.  
  70. static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  71. {
  72. steamFriends.SetPersonaState(EPersonaState.Online);
  73. }
  74.  
  75. static void OnConnected(SteamClient.ConnectedCallback callback)
  76. {
  77. if (callback.Result != EResult.OK)
  78. {
  79. Console.WriteLine("Unable to connect to Steam: {0}", callback.Result);
  80.  
  81. isRunning = false;
  82. return;
  83. }
  84.  
  85. Console.WriteLine("Connected to Steam! Logging in '{0}'...", user);
  86.  
  87. byte[] sentryHash = null;
  88. if (File.Exists("sentry.bin"))
  89. {
  90. // if we have a saved sentry file, read and sha-1 hash it
  91. byte[] sentryFile = File.ReadAllBytes("sentry.bin");
  92. sentryHash = CryptoHelper.SHAHash(sentryFile);
  93. }
  94.  
  95. steamUser.LogOn(new SteamUser.LogOnDetails
  96. {
  97. Username = user,
  98. Password = pass,
  99.  
  100. // in this sample, we pass in an additional authcode
  101. // this value will be null (which is the default) for our first logon attempt
  102. AuthCode = authCode,
  103.  
  104. // if the account is using 2-factor auth, we'll provide the two factor code instead
  105. // this will also be null on our first logon attempt
  106. TwoFactorCode = twoFactorAuth,
  107.  
  108. // our subsequent logons use the hash of the sentry file as proof of ownership of the file
  109. // this will also be null for our first (no authcode) and second (authcode only) logon attempts
  110. SentryFileHash = sentryHash,
  111. });
  112. }
  113.  
  114. static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  115. {
  116. // after recieving an AccountLogonDenied, we'll be disconnected from steam
  117. // so after we read an authcode from the user, we need to reconnect to begin the logon flow again
  118.  
  119. Console.WriteLine("Disconnected from Steam, reconnecting in 5...");
  120.  
  121. Thread.Sleep(TimeSpan.FromSeconds(5));
  122.  
  123. steamClient.Connect();
  124. }
  125.  
  126. static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  127. {
  128. bool isSteamGuard = callback.Result == EResult.AccountLogonDenied;
  129. bool is2FA = callback.Result == EResult.AccountLoginDeniedNeedTwoFactor;
  130.  
  131. if (isSteamGuard || is2FA)
  132. {
  133. Console.WriteLine("This account is SteamGuard protected!");
  134.  
  135. if (is2FA)
  136. {
  137. Console.Write("Please enter your 2 factor auth code from your authenticator app: ");
  138. twoFactorAuth = Console.ReadLine();
  139. }
  140. else
  141. {
  142. Console.Write("Please enter the auth code sent to the email at {0}: ", callback.EmailDomain);
  143. authCode = Console.ReadLine();
  144. }
  145.  
  146. return;
  147. }
  148.  
  149. if (callback.Result != EResult.OK)
  150. {
  151. Console.WriteLine("Unable to logon to Steam: {0} / {1}", callback.Result, callback.ExtendedResult);
  152.  
  153. isRunning = false;
  154. return;
  155. }
  156.  
  157. Console.WriteLine("Successfully logged on!");
  158.  
  159. // at this point, we'd be able to perform actions on Steam
  160. }
  161.  
  162. static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  163. {
  164. Console.WriteLine("Logged off of Steam: {0}", callback.Result);
  165. }
  166.  
  167. static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
  168. {
  169. Console.WriteLine("Updating sentryfile...");
  170.  
  171. // write out our sentry file
  172. // ideally we'd want to write to the filename specified in the callback
  173. // but then this sample would require more code to find the correct sentry file to read during logon
  174. // for the sake of simplicity, we'll just use "sentry.bin"
  175.  
  176. int fileSize;
  177. byte[] sentryHash;
  178. using (var fs = File.Open("sentry.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite))
  179. {
  180. fs.Seek(callback.Offset, SeekOrigin.Begin);
  181. fs.Write(callback.Data, 0, callback.BytesToWrite);
  182. fileSize = (int)fs.Length;
  183.  
  184. fs.Seek(0, SeekOrigin.Begin);
  185. using (var sha = new SHA1CryptoServiceProvider())
  186. {
  187. sentryHash = sha.ComputeHash(fs);
  188. }
  189. }
  190.  
  191. // inform the steam servers that we're accepting this sentry file
  192. steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  193. {
  194. JobID = callback.JobID,
  195.  
  196. FileName = callback.FileName,
  197.  
  198. BytesWritten = callback.BytesToWrite,
  199. FileSize = fileSize,
  200. Offset = callback.Offset,
  201.  
  202. Result = EResult.OK,
  203. LastError = 0,
  204.  
  205. OneTimePassword = callback.OneTimePassword,
  206.  
  207. SentryFileHash = sentryHash,
  208. });
  209.  
  210. Console.WriteLine("Done!");
  211. }
  212. static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  213. {
  214. if (callback.EntryType == EChatEntryType.ChatMsg)
  215. {
  216. if(callback.Message.Length > 1)
  217. {
  218. if(callback.Message.Remove(1) == "!")
  219. {
  220. string command = callback.Message;
  221. if(callback.Message.Contains(" "))
  222. {
  223. command = callback.Message.Remove(callback.Message.IndexOf(" "))
  224. }
  225. switch(command)
  226. {
  227. case command = "!help"
  228. break;
  229. }
  230. }
  231. }
  232.  
  233. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Hello, this is a bot");
  234. }
  235. }
  236. public static string[] seperate(int number, char seperator, string thestring)
  237. {
  238. string[] returned = new string[4]
  239.  
  240. int i = 0;
  241.  
  242. int error = 0;
  243.  
  244. int length = thestring.length;
  245.  
  246. foreach
  247.  
  248. if(int != number)
  249. {
  250. if(error > lenghth || number > 5)
  251. {
  252. returned[0] = "-1";
  253. return returned;
  254. }
  255. else if(char == seperator)
  256. {
  257. returned[i] = thestring.Remove(thestring.IndexOf(c));
  258. thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
  259. }
  260. }
  261. }
  262. }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement