Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.64 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. string[] args;
  189.  
  190. if (callback.EntryType == EChatEntryType.ChatMsg)
  191. {
  192. if (callback.Message.Length > 1)
  193. {
  194. if(callback.Message.Remove(1) == "!")
  195. {
  196. string command = callback.Message;
  197. if(callback.Message.Contains(" "))
  198. {
  199. command = callback.Message.Remove(callback.Message.IndexOf(' '));
  200. }
  201.  
  202. switch(command)
  203. {
  204. case "!send":
  205. args = seperate(2, ' ', callback.Message);
  206. Console.WriteLine("!send " + args[1] + args[2] + " command recieved. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  207. if(args[0] == "-1")
  208. {
  209. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Command syntax: !send [friend] [message]");
  210. return;
  211. }
  212. for (int i = 0; i < steamFriends.GetFriendCount(); i++)
  213. {
  214. SteamID friend = steamFriends.GetFriendByIndex(i);
  215. if(steamFriends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
  216. {
  217. steamFriends.SendChatMessage(friend, EChatEntryType.ChatMsg, args[2]);
  218. }
  219. }
  220. break;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. public static string[] seperate(int number,char seperator,string thestring)
  227. {
  228. string[] returned = new string[4];
  229.  
  230. int i = 0;
  231.  
  232. int error = 0;
  233.  
  234. int lenght = thestring.Length;
  235.  
  236. foreach(char c in thestring)
  237. {
  238. if(i != number)
  239. {
  240. if(error > lenght || number > 5)
  241. {
  242. returned[0] = "-1";
  243. return returned;
  244. }
  245. else if(c == seperator)
  246. {
  247. returned[i] = thestring.Remove(thestring.IndexOf(c));
  248. thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
  249. i++;
  250. }
  251. error++;
  252.  
  253. if(error > lenght && i != number)
  254. {
  255. returned[0] = "-1";
  256. return returned;
  257. }
  258. }
  259. else
  260. {
  261. returned[i] = thestring;
  262. }
  263. }
  264. return returned;
  265. }
  266. }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement