Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 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. if(!File.Exists("chat.txt"))
  28. {
  29. File.Create("chat.txt").Close();
  30. File.WriteAllText("chat.txt", "abc | 123");
  31. }
  32.  
  33. Console.Title = "SteamBot Console";
  34. Console.WriteLine("CTRL+C quits the program.");
  35.  
  36. Console.Write("Username: ");
  37. user = Console.ReadLine();
  38.  
  39. Console.Write("Password: ");
  40. pass = Console.ReadLine();
  41.  
  42. SteamLogIn();
  43. }
  44.  
  45. static void SteamLogIn()
  46. {
  47. steamClient = new SteamClient();
  48.  
  49. manager = new CallbackManager(steamClient);
  50.  
  51. steamUser = steamClient.GetHandler<SteamUser>();
  52.  
  53. steamFriends = steamClient.GetHandler<SteamFriends>();
  54.  
  55. new Callback<SteamClient.ConnectedCallback>(OnConnected);
  56. new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
  57.  
  58. new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
  59. new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
  60.  
  61. new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
  62. new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, manager);
  63.  
  64. new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
  65.  
  66. isRunning = true;
  67.  
  68. Console.WriteLine("Connecting to Steam...");
  69.  
  70. steamClient.Connect();
  71.  
  72.  
  73. while (isRunning)
  74. {
  75. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
  76. }
  77. Console.ReadKey();
  78. }
  79.  
  80. static void OnConnected(SteamClient.ConnectedCallback callback)
  81. {
  82. if (callback.Result != EResult.OK)
  83. {
  84. Console.WriteLine("Unable to connect to steam: {0}", callback.Result);
  85.  
  86. isRunning = false;
  87. return;
  88. }
  89.  
  90. Console.WriteLine("Connected to Steam. \nLogging in {0}... \n", user);
  91.  
  92. byte[] sentryHash = null;
  93.  
  94. if(File.Exists("sentry.bin"))
  95. {
  96. byte[] sentryFile = File.ReadAllBytes("sentry.bin");
  97.  
  98. sentryHash = CryptoHelper.SHAHash(sentryFile);
  99. }
  100.  
  101. steamUser.LogOn(new SteamUser.LogOnDetails
  102. {
  103. Username = user,
  104. Password = pass,
  105.  
  106. AuthCode = authCode,
  107.  
  108. TwoFactorCode = twofactor,
  109.  
  110. SentryFileHash = sentryHash,
  111. });
  112. }
  113.  
  114. static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  115. {
  116. if(callback.Result != EResult.AccountLogonDenied)
  117. {
  118. Console.WriteLine("Account is SteamGuard protected.");
  119.  
  120. Console.Write("Please enter the authentication code sent to the email at {0}: ", callback.EmailDomain);
  121.  
  122. authCode = Console.ReadLine();
  123.  
  124. return;
  125. }
  126.  
  127. {
  128. if (callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode)
  129. {
  130. Console.WriteLine("Please enter your authentication code\n");
  131.  
  132. twofactor = Console.ReadLine();
  133.  
  134. return;
  135. }
  136. }
  137.  
  138. if(callback.Result != EResult.OK)
  139. {
  140. Console.WriteLine("Unable to log in to Steam: {0}\n", callback.Result);
  141. isRunning = false;
  142. return;
  143. }
  144. Console.WriteLine("{0} succesfully logged in.", user);
  145.  
  146. }
  147.  
  148. static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback, JobID jobID)
  149. {
  150. Console.WriteLine("Updating sentry file...");
  151.  
  152. byte[] sentryHash = CryptoHelper.SHAHash(callback.Data);
  153.  
  154. File.WriteAllBytes("sentry.bin", callback.Data);
  155.  
  156. steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
  157. {
  158. JobID = jobID,
  159. FileName = callback.FileName,
  160. BytesWritten = callback.BytesToWrite,
  161. FileSize = callback.Data.Length,
  162. Offset = callback.Offset,
  163. Result = EResult.OK,
  164. LastError = 0,
  165. OneTimePassword = callback.OneTimePassword,
  166. SentryFileHash = sentryHash,
  167. });
  168.  
  169. Console.WriteLine("Done.");
  170. }
  171.  
  172. static void OnDisconnected(SteamClient.DisconnectedCallback callback)
  173. {
  174. Console.WriteLine("\n {0} disconnected from Steam, reconnecting in 5...\n", user);
  175.  
  176. Thread.Sleep(TimeSpan.FromSeconds(5));
  177.  
  178. steamClient.Connect();
  179. }
  180.  
  181. static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
  182. {
  183. Console.WriteLine("Logged off from Steam: {0}", callback.Result);
  184. }
  185.  
  186. static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  187. {
  188. steamFriends.SetPersonaState(EPersonaState.Online);
  189.  
  190. }
  191.  
  192. static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  193. {
  194. string[] args;
  195.  
  196. if (callback.EntryType == EChatEntryType.ChatMsg)
  197. {
  198. if (callback.Message.Length > 1)
  199. {
  200. if(callback.Message.Remove(1) == "!")
  201. {
  202. string command = callback.Message;
  203. if(callback.Message.Contains(" "))
  204. {
  205. command = callback.Message.Remove(callback.Message.IndexOf(' '));
  206. }
  207.  
  208. switch(command)
  209. {
  210. #region send
  211. case "!send":
  212. args = seperate(2, ' ', callback.Message);
  213. Console.WriteLine("!send " + args[1] + args[2] + " command recieved. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  214. if(args[0] == "-1")
  215. {
  216. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Command syntax: !send [friend] [message]");
  217. return;
  218. }
  219. for (int i = 0; i < steamFriends.GetFriendCount(); i++)
  220. {
  221. SteamID friend = steamFriends.GetFriendByIndex(i);
  222. if(steamFriends.GetFriendPersonaName(friend).ToLower().Contains(args[1].ToLower()))
  223. {
  224. steamFriends.SendChatMessage(friend, EChatEntryType.ChatMsg, args[2]);
  225. }
  226. }
  227. break;
  228. #endregion
  229. #region friends
  230. case "!friends":
  231. Console.WriteLine("!friends command recieved. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  232. for (int i = 0; i < steamFriends.GetFriendCount(); i++)
  233. {
  234. SteamID friend = steamFriends.GetFriendByIndex(i);
  235. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Friend: " + steamFriends.GetFriendPersonaName(friend) + " State: " + steamFriends.GetFriendPersonaState(friend));
  236. }
  237. break;
  238. #endregion
  239. }
  240. }
  241. }
  242. string rLine;
  243. string trimmed = callback.Message;
  244.  
  245. char[] trim = { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', ']', '{', '}', '\\', '|', ';', ':', '"', '\'', ',', '<', '.', '>', '/', '?' };
  246.  
  247. for(int i = 0; i < 30; i++)
  248. {
  249. trimmed = trimmed.Replace(trim[i].ToString(), "");
  250. }
  251.  
  252. StreamReader sReader = new StreamReader("chat.txt");
  253.  
  254. while((rLine = sReader.ReadLine()) != null)
  255. {
  256. string text = rLine.Remove(rLine.IndexOf('|') - 1);
  257. string response = rLine.Remove(0, rLine.IndexOf('|') + 2);
  258.  
  259. if(callback.Message.Contains(text))
  260. {
  261. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, response);
  262. sReader.Close();
  263. return;
  264. }
  265. }
  266.  
  267. }
  268. }
  269.  
  270. public static string[] seperate(int number,char seperator,string thestring)
  271. {
  272. string[] returned = new string[4];
  273.  
  274. int i = 0;
  275.  
  276. int error = 0;
  277.  
  278. int lenght = thestring.Length;
  279.  
  280. foreach(char c in thestring)
  281. {
  282. if(i != number)
  283. {
  284. if(error > lenght || number > 5)
  285. {
  286. returned[0] = "-1";
  287. return returned;
  288. }
  289. else if(c == seperator)
  290. {
  291. returned[i] = thestring.Remove(thestring.IndexOf(c));
  292. thestring = thestring.Remove(0, thestring.IndexOf(c) + 1);
  293. i++;
  294. }
  295. error++;
  296.  
  297. if(error > lenght && i != number)
  298. {
  299. returned[0] = "-1";
  300. return returned;
  301. }
  302. }
  303. else
  304. {
  305. returned[i] = thestring;
  306. }
  307. }
  308. return returned;
  309. }
  310. }
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement