Advertisement
Guest User

Untitled

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