using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.IO;
using WindowsInput;
namespace Dice999Starter
{
class Dice999Starter
{
static Process[] processes = null;
static void Main(string[] args)
{
start(true);
while (true)
{
Thread.Sleep(2000);
for (int i = 0; i < botsNumber; i++)
{
try
{
Process process = Process.GetProcessById(processes[i].Id);
//Console.WriteLine("Is alive...");
}
catch
{
//Console.WriteLine(i + " killed...");
processes[i] = null;
}
}
start(false);
}
}
static int botsNumber = 0;
static string refLink;
static void start(bool init)
{
try
{
string currentDirectory = Directory.GetCurrentDirectory();
if (init)
{
var data = new Dictionary<string, string>();
foreach (var row in File.ReadAllLines(currentDirectory + @"\..\..\..\..\starterCfg.txt"))
{
string key = row.Substring(0, row.IndexOf("=")).Trim();
string value = row.Substring(row.IndexOf("=") + 1).Trim();
data.Add(key, value);
}
botsNumber = Int32.Parse(data["bots"], System.Globalization.CultureInfo.InvariantCulture);
processes = new Process[botsNumber];
refLink = data["refLink"];
Console.WriteLine("bots number: " + botsNumber);
Console.WriteLine("refLink: " + refLink);
}
int w;
int h;
int m;
if (botsNumber <= 24)
{
w = 1920 / 6;
h = 1080 / 4;
m = 6;
}
else
{
w = 1920 / 6;
h = 1080 / 14;
m = 6;
}
for (int i = 0; i < botsNumber; i++)
{
string appName = "bot" + i;
if (init)
{
int x = i % m * w;
int y = i / m * h;
if (!Directory.Exists(currentDirectory + @"\..\..\..\..\logs"))
{
Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\logs");
}
if (!File.Exists(currentDirectory + @"\..\..\..\..\logs\" + appName + @"Log.txt") || init)
{
FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\logs\" + appName + @"Log.txt");
fs.Close();
}
if (!Directory.Exists(currentDirectory + @"\..\..\..\..\properties"))
{
Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\properties");
}
if (!File.Exists(currentDirectory + @"\..\..\..\..\properties\" + appName + @"Property.txt"))
{
FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\properties\" + appName + @"Property.txt");
fs.Close();
}
if (!Directory.Exists(currentDirectory + @"\..\..\..\..\configs"))
{
Directory.CreateDirectory(currentDirectory + @"\..\..\..\..\configs");
}
//if (!File.Exists(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Config.txt"))
{
FileStream fs = File.Create(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Cfg.txt");
fs.Close();
}
//string currentDirectory = Directory.GetCurrentDirectory();
using (StreamWriter wrt = File.AppendText(currentDirectory + @"\..\..\..\..\configs\" + appName + @"Cfg.txt"))
{
wrt.Write("x=" + x);
wrt.Write("\r\ny=" + y);
wrt.Write("\r\nw=" + w);
wrt.Write("\r\nh=" + h);
wrt.Close();
}
}
if (processes[i] == null)
{
if (File.Exists(currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt"))
{
File.Delete(currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt");
}
File.Copy(currentDirectory + @"\..\..\..\..\proxies.txt", currentDirectory + @"\..\..\..\..\proxies\" + appName + @"Proxy.txt");
string[] argsToPass = { "bot" + i, refLink };
processes[i] = Process.Start(@"currentDirectory\..\..\..\..\..\Dice999uBot\Dice999uBot\bin\Release\Dice999uBot.exe", String.Join(" ", argsToPass));
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}