Advertisement
Guest User

Untitled

a guest
Apr 9th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.80 KB | None | 0 0
  1. using SteamKit2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Net.Sockets;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Web.Script.Serialization;
  11. using System.Runtime.InteropServices;
  12. using System.Linq;
  13.  
  14. namespace L3dg3ndBot___Steam_bot
  15. {
  16. internal class Program
  17. {
  18. static string path = @"C:\Program Files (x86)\Steam\steamapps\common\Unturned\";
  19. private const int APPID = 0x4a722;
  20. private static string authCode;
  21. private static RootObject config;
  22. private static bool isRunning = false;
  23. private static CallbackManager manager;
  24. private static string pass;
  25. private static SteamClient steamClient;
  26. private static SteamFriends steamFriends;
  27. private static SteamUser steamUser;
  28. private static string user;
  29.  
  30. private static string inputPass()
  31. {
  32. string str = "";
  33. bool flag = true;
  34. while (flag)
  35. {
  36. char keyChar = Console.ReadKey(true).KeyChar;
  37. if (keyChar == '\r')
  38. {
  39. flag = false;
  40. Console.WriteLine();
  41. }
  42. else if ((keyChar == '\b') && (str.Length > 0))
  43. {
  44. Console.CursorLeft--;
  45. Console.Write(' ');
  46. Console.CursorLeft--;
  47. str = str.Substring(0, str.Length - 1);
  48. }
  49. else
  50. {
  51. str = str + keyChar.ToString();
  52. Console.Write("*");
  53. }
  54. }
  55. return str;
  56. }
  57.  
  58. public static bool isBotAdmin(SteamID sid)
  59. {
  60. try
  61. {
  62. foreach (ulong num in config.Admins)
  63. {
  64. if (num == sid)
  65. {
  66. return true;
  67. }
  68. }
  69. steamFriends.SendChatMessage(sid, EChatEntryType.ChatMsg, "ATTENTION - YOU ARE NOT AN ADMIN");
  70. Console.WriteLine(steamFriends.GetFriendPersonaName(sid) + " attempted to use an Administrator command while not an Administrator, your actions have been saved for Admins to see!");
  71. }
  72. catch (Exception exception)
  73. {
  74. Console.WriteLine(exception.Message);
  75. return false;
  76. }
  77. return false;
  78. }
  79.  
  80. public static bool isBotMod1(SteamID sid)
  81. {
  82. try
  83. {
  84. foreach (ulong num in config.Moderators)
  85. {
  86. if (num == sid)
  87. {
  88. return true;
  89. }
  90. }
  91. foreach (ulong num2 in config.Admins)
  92. {
  93. if (num2 == sid)
  94. {
  95. return true;
  96. }
  97. }
  98. steamFriends.SendChatMessage(sid, EChatEntryType.ChatMsg, "ATTENTION - YOU ARE NOT AN ADMIN / MOD");
  99. Console.WriteLine(steamFriends.GetFriendPersonaName(sid) + " attempted to use an Administrator command while not an Administrator, your actions have been saved for Admins to see!");
  100. }
  101. catch (Exception exception)
  102. {
  103. Console.WriteLine(exception.Message);
  104. return false;
  105. }
  106. return false;
  107. }
  108.  
  109. public static bool isGroupBotAdmin(SteamFriends.ChatMsgCallback sid)
  110. {
  111. try
  112. {
  113. if (sid.ChatterID.ConvertToUInt64() == Convert.ToUInt64(System.IO.File.ReadAllText("admin.cfg")))
  114. {
  115. return true;
  116. }
  117. steamFriends.SendChatRoomMessage(sid.ChatterID.ConvertToUInt64(), EChatEntryType.ChatMsg, "ATTENTION - YOU ARE NOT AN ADMIN");
  118. Console.WriteLine(steamFriends.GetFriendPersonaName(sid.ChatterID.ConvertToUInt64()) + " attempted to use an Administrator command while not an Administrator, your actions have been saved for Admins to see!");
  119. }
  120. catch (Exception exception)
  121. {
  122. Console.WriteLine(exception.Message);
  123. return false;
  124. }
  125. return false;
  126. }
  127.  
  128. private static void Main(string[] args)
  129. {
  130.  
  131. Console.Title = "L3dg3ndBOT by Alexr03 (SteamBOT)";
  132. Console.ForegroundColor = ConsoleColor.Yellow;
  133. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] L3dg3ndBOT was made by Alexr03 and doesn't collect ANY of information." }));
  134. Console.ForegroundColor = ConsoleColor.Cyan;
  135. Console.WriteLine("");
  136. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] Loading... Please wait..." }));
  137. Thread.Sleep(0xdac);
  138. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] Reloading configuration..." }));
  139. reloadConfig();
  140. Thread.Sleep(0x5dc);
  141. Console.Clear();
  142. Console.WriteLine("");
  143. Thread.Sleep(100);
  144. Console.ForegroundColor = ConsoleColor.Red;
  145. Console.WriteLine("Do note you are running a beta version of this software, so be greatful twats!");
  146. Console.ForegroundColor = ConsoleColor.Green;
  147. Console.WriteLine("");
  148. Console.WriteLine("");
  149. Console.WriteLine(".-. .----. .-. .----. .-. .-- -. .--. .---- -.");
  150. Thread.Sleep(100);
  151. Console.WriteLine(": : `-- ; : : `-- ; : : : .; :: ,. :`-. .-'");
  152. Thread.Sleep(100);
  153. Console.WriteLine(": : .' ' .-' : .--. .' ' ,-.,-. .-' : : .': :: : : : ");
  154. Thread.Sleep(100);
  155. Console.WriteLine(": :__ _`,`.' .; :' .; : _`,`.: ,. :' .; : : .; :: :; : : : ");
  156. Thread.Sleep(100);
  157. Console.WriteLine(":___.'`.__.'`.__.'`._. ;`.__.':_;:_;`.__.' :___.'`.__.' :_; ");
  158. Thread.Sleep(100);
  159. Console.WriteLine(" .-. : ");
  160. Thread.Sleep(100);
  161. Console.WriteLine(" `._.' ");
  162. Thread.Sleep(100);
  163. Console.WriteLine("");
  164. Thread.Sleep(100);
  165. Console.WriteLine(" SolarSenHosting Servers - Alexr03 2016 ");
  166. Thread.Sleep(100);
  167. Console.WriteLine("");
  168. Thread.Sleep(100);
  169. Console.WriteLine("");
  170. Console.ForegroundColor = ConsoleColor.Yellow;
  171. Thread.Sleep(100);
  172. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] L3dg3ndBOT was made by Alexr03 and doesn't collect ANY of information. :D" }));
  173. Thread.Sleep(100);
  174. Console.ForegroundColor = ConsoleColor.White;
  175. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] [L3dg3ndBOT Says: ] You need to login to Steam." }));
  176. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] [L3dg3ndBOT Says: ] What is your Steam Username?" }));
  177. Console.ForegroundColor = ConsoleColor.Green;
  178. Console.Write("Username: ");
  179. user = Console.ReadLine();
  180. Console.ForegroundColor = ConsoleColor.Yellow;
  181. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] [L3dg3ndBOT Says: ] Great! Now lets move on to the next part." }));
  182. Thread.Sleep(200);
  183. Console.WriteLine(string.Concat(new object[] { "[ ", DateTime.Now.Hour, ":", DateTime.Now.Minute, " ] [L3dg3ndBOT Says: ] What is your Steam Password?" }));
  184. Console.ForegroundColor = ConsoleColor.Green;
  185. Console.Write("Password: ");
  186. pass = inputPass();
  187. SteamLogIn();
  188. }
  189.  
  190. private static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
  191. {
  192. steamFriends.SetPersonaState(EPersonaState.Online);
  193. }
  194.  
  195. private static void OnChatEnter(SteamFriends.ChatEnterCallback callback)
  196. {
  197. steamFriends.SendChatRoomMessage(callback.ChatID, EChatEntryType.ChatMsg, "What a nice chatroom! :steamhappy:");
  198. }
  199.  
  200. private static void OnChatInvite(SteamFriends.ChatInviteCallback callback)
  201. {
  202. steamFriends.JoinChat(callback.ChatRoomID);
  203. Console.WriteLine(string.Concat(new object[] { user, " has been invited to ", callback.ChatRoomName, "'s group chat! (", callback.ChatRoomID, ")" }));
  204. }
  205.  
  206. static void OnChatMessage(SteamFriends.FriendMsgCallback callback)
  207. {
  208. //This allows us to send a callback.Message, callback.Sender is the steam ID
  209. //of the friend who sent the callback.Message, therefore we can use it
  210. //for the SendChatMessage function which requires a steam ID
  211. //Then, chat entry type is set to chat callback.Message in order to
  212. //inform steam we are sending a text based callback.Message
  213. //and not a "x user is typing..." or something like that
  214.  
  215. //this if statement prevents the bot from saqying something every while you're typing
  216. //because the "x user is typing..." is interperated as a steam callback.Message, so
  217. //we need to check if it's an actual chat callback.Message
  218.  
  219. //we're going to create a switch statement to mass-check the arguements.
  220.  
  221. //but first we need to check if the chat callback.Message has a valid length to keep the .Remove() from crashing
  222.  
  223. if (callback.Message.Length > 1)
  224. {
  225. //we check the first character of the callback.Message for the valid command prefix
  226. if (callback.Message.Remove(1) == "/")
  227. {
  228. //we set a string equal to the callback.Message so we can manipulate it without screwing up the original callback.Message
  229. string command = callback.Message;
  230. //check to see if the callback.Message contains a space so we can then remove everything after it, so we can check the command. For example: !friend [sid64] becomes !friend.
  231. if (callback.Message.Contains(' '))
  232. {
  233. //set the string command equal to its stripped counterpart. !friend [sid64] becomes !friend for the switch statement later on
  234. command = callback.Message.Remove(callback.Message.IndexOf(' '));
  235. }
  236.  
  237. /*now we use a switch statement, which is basically like a cascaded if statement. Instead of writing
  238. * if(command == "!send")
  239. * { stuff; }
  240. *
  241. * else if (command == "!friend")
  242. * { stuff; }
  243. *
  244. * we write
  245. *
  246. * switch(command)
  247. * {
  248. * case "!send":
  249. * stuff;
  250. * break;
  251. *
  252. * case "!friend":
  253. * stuff;
  254. * break;
  255. * }
  256. *
  257. * Which is much clearer and easier to write
  258. */
  259.  
  260. string[] strArray;
  261. string[] args; //set up an array string for our future args
  262. switch (command)
  263. {
  264. //check the command to see if it is "!send"
  265. case "/start":
  266. //first we need to create a seperation function to seperate the args. so !friend [sid64] becomes args[0] = "!friend", args[1] = "sid64"
  267. //okay, now that we've got that, we need to keep people that aren't allowed to use the command from using it. See: isBotAdmin
  268. if (!isBotAdmin(callback.Sender)) //is the person not a bot admin?
  269. return; //exit function without executing commands.
  270. //seperate our arguments into 3 parts using our seperate function
  271. args = Seperate(2, ' ', callback.Message); //args[0] = !send, args[1] = friend to send to, args[2] = callback.Message
  272. Console.WriteLine("/start " + args[1] + " " + args[2] + " command received. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  273.  
  274. if (args[0] == "-1") //see if the number of expected arguments was not received
  275. {
  276. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Processing your request for startup!");
  277. start();
  278. }
  279. break;
  280.  
  281. case "/changename":
  282. if (!isBotAdmin(callback.Sender))
  283. {
  284. return;
  285. }
  286. strArray = seperate(1, ' ', callback.Message);
  287. Console.WriteLine("/changename " + strArray[1] + " command received. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  288. if (strArray[0] == "-1")
  289. {
  290. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Syntax: /changename [name]");
  291. return;
  292. }
  293. steamFriends.SetPersonaName(strArray[1]);
  294.  
  295. break;
  296.  
  297. case "/botstatus":
  298. if (!isBotAdmin(callback.Sender))
  299. {
  300. return;
  301. }
  302. strArray = seperate(1, ' ', callback.Message);
  303. Console.WriteLine("/botstatus " + strArray[1] + " command received. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  304. if (strArray[0] == "-1")
  305. {
  306. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Syntax: /botstatus [status]");
  307. return;
  308. }
  309. if (strArray[1] == "online")
  310. {
  311. steamFriends.SetPersonaState(EPersonaState.Online);
  312. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Status changed to Online");
  313. }
  314. if (strArray[1] == "busy")
  315. {
  316. steamFriends.SetPersonaState(EPersonaState.Busy);
  317. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Status changed to Busy");
  318. }
  319. if (strArray[1] == "away")
  320. {
  321. steamFriends.SetPersonaState(EPersonaState.Away);
  322. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Status changed to Away");
  323. }
  324.  
  325. break;
  326.  
  327. case "/shutdown":
  328. if (!isBotAdmin(callback.Sender))
  329. return;
  330. args = Seperate(2, ' ', callback.Message);
  331. Console.WriteLine("/shutdown " + args[1] + " " + args[2] + " command received. User: " + steamFriends.GetFriendPersonaName(callback.Sender));
  332.  
  333. if (args[0] == "-1")
  334. {
  335. steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Processing your request for shutdown!");
  336. shutdown();
  337. }
  338. break;
  339. }
  340. return;
  341. }
  342. }
  343.  
  344. //now that we've got a config and a "Chatty" variable, let's make it so you can tell the bot to talk or not
  345.  
  346. if (!config.Chatty)
  347. return;
  348. //if the bot is not chatty, exit.
  349.  
  350. //before we start off, go to main() and work with the chat.txt
  351. //we'll need two string variables, one to hold the trimed version of the callback.Message, and another to hold the read line.
  352. string trimmed = callback.Message; //we can just set it here for now
  353. //we also need an array of the characters we need to trim from the callback.Message
  354. char[] trim = { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', ']', '{', '}', '\\', '|', ';', ':', '"', '\'', ',', '<', '.', '>', '/', '?' };
  355.  
  356. //now we need to create a stream reader to read the file that contains all of our chat lines
  357. }
  358. //we create a seperation function to make checking and using arguements much easier
  359. // number of arguements -1 v seperation char the string to seperate | the number of arguements - 1 is due to the fact that each arguement is preceded by one space, so "!friend [sid64]" has two args, but only one space.
  360. public static string[] Seperate(int number, char seperator, string thestring)
  361. {
  362. //we create a return array, set v to the max number of arguements ANY of your commands will take.
  363. string[] returned = new string[4];
  364. //create a counter variable
  365. int i = 0;
  366. //create an error variable to check for errors in the string
  367. int error = 0;
  368. //Get the length of the command so we can check it against the error variable to see if the number of arguements expected equaled the number of arguements recieved. for example "!friend" takes two arguements
  369. //if it were to only recieve one, once "error" equaled the string length and "i" was not equal to the expected number of arguements, we would return an error and handle it inside the switch statement
  370. //such as sending a chat callback.Message of the command's syntax
  371. int length = thestring.Length;
  372. //check each char in a foreach loop
  373. foreach (char s in thestring)
  374. {
  375. //check to see if the number of arguements expected has been reached yet
  376. if (i != number)
  377. {
  378. //check to see if the number of arguements expected wasn't reached, or if too many were recieved
  379. if (error > length || number > 5)
  380. {
  381. //return an error code
  382. returned[0] = "-1";
  383. return returned;
  384. }
  385. //check to see if the current character is equal to our seperator, so we can then isolate it and move it into the appropriate args[x]
  386. else if (s == seperator)
  387. {
  388. returned[i] = thestring.Remove(thestring.IndexOf(s));
  389. thestring = thestring.Remove(0, thestring.IndexOf(s) + 1);
  390. i++;
  391. }
  392. //increment error after each iteration
  393. error++;
  394. //check to see if the # of arguements expected was not reached
  395. if (error == length && i != number)
  396. {
  397. returned[0] = "-1";
  398. return returned;
  399. }
  400. }
  401.  
  402. else
  403. {
  404. //return the last part of the string
  405. returned[i] = thestring;
  406. }
  407. }
  408. //return our array
  409. return returned;
  410. }
  411.  
  412. private static void OnConnected(SteamClient.ConnectedCallback callback)
  413. {
  414. if (callback.Result != EResult.OK)
  415. {
  416. Console.WriteLine("L3dg3ndBOT has failed to connect!");
  417. Console.WriteLine("Error:" + callback.Result);
  418. isRunning = false;
  419. }
  420. else
  421. {
  422. Console.WriteLine("Succesfully connected to Steam! \nLogging in {0}!\n", user);
  423. byte[] buffer = null;
  424. if (System.IO.File.Exists("sentry.bin"))
  425. {
  426. buffer = CryptoHelper.SHAHash(System.IO.File.ReadAllBytes("sentry.bin"));
  427. }
  428. SteamUser.LogOnDetails details = new SteamUser.LogOnDetails
  429. {
  430. Username = user,
  431. Password = pass,
  432. AuthCode = authCode,
  433. SentryFileHash = buffer
  434. };
  435. steamUser.LogOn(details);
  436. Console.WriteLine("Connected!");
  437. if (System.IO.File.Exists("sentry.bin"))
  438. {
  439. buffer = CryptoHelper.SHAHash(System.IO.File.ReadAllBytes("sentry.bin"));
  440. }
  441. }
  442. }
  443.  
  444. private static void OnDisconnected(SteamClient.DisconnectedCallback obj)
  445. {
  446. Console.WriteLine("\n{0} disconnected from steam, attempting reconnect in 5 seconds.", user);
  447. Thread.Sleep(0x1388);
  448. steamClient.Connect(null);
  449. }
  450.  
  451. private static void onFriendAdded(SteamFriends.FriendsListCallback callback)
  452. {
  453. Thread.Sleep(0x9c4);
  454. foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList)
  455. {
  456. if (friend.Relationship == EFriendRelationship.RequestRecipient)
  457. {
  458. steamFriends.AddFriend(friend.SteamID);
  459. Thread.Sleep(500);
  460. steamFriends.SendChatMessage(friend.SteamID, EChatEntryType.ChatMsg, "Hello " + friend.SteamID + "! Succesfully added you as a friend!");
  461. }
  462. }
  463. }
  464.  
  465. private static void OnLoggedOn(SteamUser.LoggedOnCallback callback)
  466. {
  467. if (callback.Result == EResult.AccountLogonDenied)
  468. {
  469. Console.WriteLine("This account is Guarded by steam.");
  470. Console.Write("Enter auth code sent to your {0} account.", callback.EmailDomain);
  471. authCode = Console.ReadLine();
  472. }
  473. else if (callback.Result != EResult.OK)
  474. {
  475. Console.WriteLine("Unable to login: {0}\n", callback.Result);
  476. isRunning = false;
  477. }
  478. else
  479. {
  480. Console.WriteLine("{0} logged in successfully.", user);
  481. }
  482. }
  483.  
  484. public static void reloadConfig()
  485. {
  486. if (!System.IO.File.Exists("config.cfg"))
  487. {
  488. StringBuilder builder = new StringBuilder();
  489. builder.Append("{\r\n");
  490. builder.Append("\"Admins\":[76561198071072872],\r\n");
  491. builder.Append("\"Moderators\":[],\r\n");
  492. builder.Append("\"Server1Path\":@ C:/Program Files(x86)/Steam/steamapps/common/Unturned/Unturned.exe\r\n");
  493. builder.Append("\"Chatty\":true\r\n");
  494. builder.Append("}\r\n");
  495. System.IO.File.WriteAllText("config.cfg", builder.ToString());
  496. }
  497. try
  498. {
  499. config = new JavaScriptSerializer().Deserialize<RootObject>(System.IO.File.ReadAllText("config.cfg"));
  500. }
  501. catch (Exception exception)
  502. {
  503. Console.WriteLine("Error appeared : " + exception.Message);
  504. Console.ReadKey();
  505. reloadConfig();
  506. }
  507. }
  508.  
  509. public static string[] seperate(int number, char seperator, string thestring)
  510. {
  511. string[] strArray = new string[4];
  512. int index = 0;
  513. int num2 = 0;
  514. int length = thestring.Length;
  515. foreach (char ch in thestring)
  516. {
  517. if (index != number)
  518. {
  519. int num5;
  520. if ((num2 > length) || (number > 5))
  521. {
  522. strArray[0] = "-1";
  523. return strArray;
  524. }
  525. if (ch == seperator)
  526. {
  527. strArray[index] = thestring.Remove(thestring.IndexOf(ch));
  528. thestring = thestring.Remove(0, thestring.IndexOf(ch) + 1);
  529. num5 = index;
  530. index = num5 + 1;
  531. }
  532. num5 = num2;
  533. num2 = num5 + 1;
  534. if ((num2 == length) && (index != number))
  535. {
  536. strArray[0] = "-1";
  537. return strArray;
  538. }
  539. }
  540. else
  541. {
  542. strArray[index] = thestring;
  543. }
  544. }
  545. return strArray;
  546. }
  547.  
  548. private static void SteamLogIn()
  549. {
  550. steamClient = new SteamClient(ProtocolType.Tcp);
  551. manager = new CallbackManager(steamClient);
  552. steamUser = steamClient.GetHandler<SteamUser>();
  553. steamFriends = steamClient.GetHandler<SteamFriends>();
  554. new Callback<SteamClient.ConnectedCallback>(new Action<SteamClient.ConnectedCallback>(Program.OnConnected), manager);
  555. new Callback<SteamUser.LoggedOnCallback>(new Action<SteamUser.LoggedOnCallback>(Program.OnLoggedOn), manager);
  556. new Callback<SteamClient.DisconnectedCallback>(new Action<SteamClient.DisconnectedCallback>(Program.OnDisconnected), manager);
  557. new Callback<SteamKit2.SteamUser.UpdateMachineAuthCallback>(new Action<SteamKit2.SteamUser.UpdateMachineAuthCallback>(Program.UpdateMachineAuthCallback), manager);
  558. new Callback<SteamUser.AccountInfoCallback>(new Action<SteamUser.AccountInfoCallback>(Program.OnAccountInfo), manager);
  559. new Callback<SteamFriends.FriendMsgCallback>(new Action<SteamFriends.FriendMsgCallback>(Program.OnChatMessage), manager);
  560. new Callback<SteamFriends.FriendsListCallback>(new Action<SteamFriends.FriendsListCallback>(Program.onFriendAdded), manager);
  561. new Callback<SteamFriends.ChatInviteCallback>(new Action<SteamFriends.ChatInviteCallback>(Program.OnChatInvite), manager);
  562. new Callback<SteamFriends.ChatEnterCallback>(new Action<SteamFriends.ChatEnterCallback>(Program.OnChatEnter), manager);
  563. isRunning = true;
  564. steamClient.Connect(null);
  565. Console.WriteLine("Trying to connect to {0}\n", user);
  566. while (isRunning)
  567. {
  568. manager.RunWaitCallbacks(TimeSpan.FromSeconds(1.0));
  569. }
  570. }
  571.  
  572. private static void UpdateMachineAuthCallback(SteamKit2.SteamUser.UpdateMachineAuthCallback callback)
  573. {
  574. Console.WriteLine("Updating sentry file...");
  575. byte[] buffer = CryptoHelper.SHAHash(callback.Data);
  576. System.IO.File.WriteAllBytes("sentry.bin", callback.Data);
  577. SteamUser.MachineAuthDetails details = new SteamUser.MachineAuthDetails
  578. {
  579. FileName = callback.FileName,
  580. BytesWritten = callback.BytesToWrite,
  581. FileSize = callback.Data.Length,
  582. Offset = callback.Offset,
  583. Result = EResult.OK,
  584. LastError = 0,
  585. OneTimePassword = (SteamUser.MachineAuthDetails.OTPDetails)callback.OneTimePassword
  586. };
  587. steamUser.SendMachineAuthResponse(details);
  588. Console.WriteLine("Done!");
  589. }
  590. static void start()
  591. {
  592. try
  593. {
  594.  
  595. Console.WriteLine("Unturned is starting now.");
  596. Console.WriteLine("Starting...");
  597. System.Threading.Thread.Sleep(500);
  598. Process Unturned = new Process();
  599. Unturned.StartInfo.FileName = RootObject.Server1Path;
  600. Unturned.EnableRaisingEvents = true;
  601. Unturned.Start();
  602.  
  603. }
  604.  
  605. catch (Exception e)
  606. {
  607. Console.WriteLine(e.Message);
  608. }
  609.  
  610. }
  611. static void shutdown()
  612. {
  613. try
  614. {
  615. foreach (Process proc in Process.GetProcessesByName("Unturned"))
  616. {
  617. proc.Kill();
  618. }
  619. }
  620. catch (Exception ex)
  621. {
  622. Console.Write(ex.Message);
  623. }
  624. }
  625.  
  626. public class RootObject
  627. {
  628. public List<ulong> Admins { get; set; }
  629.  
  630. public bool Chatty { get; set; }
  631.  
  632. public List<ulong> Moderators { get; set; }
  633.  
  634. public static string Server1Path { get; set; }
  635.  
  636. }
  637. }
  638. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement