Untitled


SUBMITTED BY: Guest

DATE: June 9, 2014, 4:28 p.m.

FORMAT: Text only

SIZE: 6.5 kB

HITS: 58521

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.IO;
  9. using WindowsInput;
  10. namespace Dice999Starter
  11. {
  12. class Dice999Starter
  13. {
  14. static Process[] processes = null;
  15. static void Main(string[] args)
  16. {
  17. start(true);
  18. while (true)
  19. {
  20. Thread.Sleep(2000);
  21. for (int i = 0; i < botsNumber; i++)
  22. {
  23. try
  24. {
  25. Process process = Process.GetProcessById(processes[i].Id);
  26. //Console.WriteLine("Is alive...");
  27. }
  28. catch
  29. {
  30. //Console.WriteLine(i + " killed...");
  31. processes[i] = null;
  32. }
  33. }
  34. start(false);
  35. }
  36. }
  37. static int botsNumber = 0;
  38. static string refLink;
  39. static void start(bool init)
  40. {
  41. try
  42. {
  43. string currentDirectory = Directory.GetCurrentDirectory();
  44. if (init)
  45. {
  46. var data = new Dictionary<string, string>();
  47. foreach (var row in File.ReadAllLines(currentDirectory + @"\..\..\..\..\starterCfg.txt"))
  48. {
  49. string key = row.Substring(0, row.IndexOf("=")).Trim();
  50. string value = row.Substring(row.IndexOf("=") + 1).Trim();
  51. data.Add(key, value);
  52. }
  53. botsNumber = Int32.Parse(data["bots"], System.Globalization.CultureInfo.InvariantCulture);
  54. processes = new Process[botsNumber];
  55. refLink = data["refLink"];
  56. Console.WriteLine("bots number: " + botsNumber);
  57. Console.WriteLine("refLink: " + refLink);
  58. }
  59. int w;
  60. int h;
  61. int m;
  62. if (botsNumber <= 24)
  63. {
  64. w = 1920 / 6;
  65. h = 1080 / 4;
  66. m = 6;
  67. }
  68. else
  69. {
  70. w = 1920 / 6;
  71. h = 1080 / 14;
  72. m = 6;
  73. }
  74. for (int i = 0; i < botsNumber; i++)
  75. {
  76. string appName = "bot" + i;
  77. if (init)
  78. {
  79. int x = i % m * w;
  80. int y = i / m * h;
  81. if (!Directory.Exists(currentDirectory + @"\..\..\..\..\logs"))
  82. {
  83. Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\logs");
  84. }
  85. if (!File.Exists(currentDirectory + @"\..\..\..\..\logs\" + appName + @"Log.txt") || init)
  86. {
  87. FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\logs\" + appName + @"Log.txt");
  88. fs.Close();
  89. }
  90. if (!Directory.Exists(currentDirectory + @"\..\..\..\..\properties"))
  91. {
  92. Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\properties");
  93. }
  94. if (!File.Exists(currentDirectory + @"\..\..\..\..\properties\" + appName + @"Property.txt"))
  95. {
  96. FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\properties\" + appName + @"Property.txt");
  97. fs.Close();
  98. }
  99. if (!Directory.Exists(currentDirectory + @"\..\..\..\..\configs"))
  100. {
  101. Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\configs");
  102. }
  103. //if (!File.Exists(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Config.txt"))
  104. {
  105. FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Cfg.txt");
  106. fs.Close();
  107. }
  108. //string currentDirectory = Directory.GetCurrentDirectory();
  109. using (StreamWriter wrt = File.AppendText(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Cfg.txt"))
  110. {
  111. wrt.Write("x=" + x);
  112. wrt.Write("\r\ny=" + y);
  113. wrt.Write("\r\nw=" + w);
  114. wrt.Write("\r\nh=" + h);
  115. wrt.Close();
  116. }
  117. }
  118. if (processes[i] == null)
  119. {
  120. if (File.Exists(currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt"))
  121. {
  122. File.Delete(currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt");
  123. }
  124. File.Copy(currentDirectory + @"\..\..\..\..\proxies.txt", currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt");
  125. string[] argsToPass = { "bot" + i, refLink };
  126. processes[i] = Process.Start(@"currentDirectory\..\..\..\..\..\Dice999uBot\Dice999uBot\bin\Release\Dice999uBot.exe", String.Join(" ", argsToPass));
  127. }
  128. }
  129. }
  130. catch (Exception e)
  131. {
  132. Console.WriteLine(e);
  133. }
  134. }
  135. }
  136. }

comments powered by Disqus