Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Reload/stop when detecting a changes in bot config.
Browse files Browse the repository at this point in the history
  • Loading branch information
alvr committed Nov 1, 2016
1 parent 43a44d9 commit 2db2d42
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 71 deletions.
116 changes: 48 additions & 68 deletions ASFui/ASFProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public class ASFProcess
private readonly ASFui _asf;
private Process ASF;
private readonly RichTextBox output;
private Thread outputThread;
private readonly StringBuilder sb = new StringBuilder();
private bool loaded;
private string key;
private volatile bool closeOutput;

Expand Down Expand Up @@ -53,77 +51,55 @@ public ASFProcess(ASFui asf, RichTextBox rtb)

private void PrintOutput()
{
try
int s;
while ((ASF != null && (s = ASF.StandardOutput.Read()) != 0) && !closeOutput)
{
int s;
while ((s = ASF.StandardOutput.Read()) != 0 || !closeOutput || ASF != null)
MethodInvoker mi = delegate
{
MethodInvoker mi = delegate
{
key = Regex.Match(sb.ToString(), @"[0-9A-Z]{5}-[0-9A-Z]{5}-[0-9A-Z]{5}", RegexOptions.IgnoreCase).Value;
output.AppendText(sb.ToString());
Check();
output.SelectionStart = output.Text.Length;
output.ScrollToCaret();
sb.Clear();
};

try
{
sb.Append(Convert.ToChar(s));
}
catch (OverflowException e)
{
Logging.Exception(e, "Output too long.");
sb.Clear();
}

if (s == '\n')
{
output.Invoke(mi);
}

if (sb.ToString().EndsWith("\"android:\"):") || sb.ToString().EndsWith("login:") ||
sb.ToString().EndsWith("+1234567890):") || sb.ToString().EndsWith("mobile:") ||
sb.ToString().EndsWith("email:") || sb.ToString().EndsWith("PIN:") ||
sb.ToString().EndsWith("app:") || sb.ToString().EndsWith("hostname:"))
{
output.AppendText(sb + " ");
var result = Interaction.InputBox(sb.ToString(), @"Enter necessary input");
ASF.StandardInput.WriteLine(result);
ASF.StandardInput.Flush();
output.AppendText(result + Environment.NewLine + sb);
sb.Clear();
}

else if ((!sb.ToString().StartsWith("[AES]") ^ sb.ToString().StartsWith("[ProtectedDataForCurrentUser]"))
&& sb.ToString().EndsWith("password:"))
{
var Password = new Password(ASF, sb.ToString());
Password.ShowDialog();
}

else if (sb.ToString().EndsWith("running, exiting"))
{
sb.Clear();
_asf.btnStop.Invoke(new MethodInvoker(delegate { _asf.btnStop.PerformClick(); }));
}
key = Regex.Match(sb.ToString(), @"[0-9A-Z]{5}-[0-9A-Z]{5}-[0-9A-Z]{5}", RegexOptions.IgnoreCase).Value;
output.AppendText(sb.ToString());
Check();
output.SelectionStart = output.Text.Length;
output.ScrollToCaret();
sb.Clear();
};

sb.Append(Convert.ToChar(s));

if (s == '\n')
{
output.Invoke(mi);
}
}
catch (NullReferenceException e)
{
Logging.Exception(e, "Error reading ASF output.");
sb.Clear();
_asf.btnStop.Invoke(new MethodInvoker(delegate { _asf.btnStop.PerformClick(); }));

if (sb.ToString().EndsWith("\"android:\"):") || sb.ToString().EndsWith("login:") ||
sb.ToString().EndsWith("+1234567890):") || sb.ToString().EndsWith("mobile:") ||
sb.ToString().EndsWith("email:") || sb.ToString().EndsWith("PIN:") ||
sb.ToString().EndsWith("app:") || sb.ToString().EndsWith("hostname:"))
{
output.AppendText(sb + " ");
var result = Interaction.InputBox(sb.ToString(), @"Enter necessary input");
ASF.StandardInput.WriteLine(result);
ASF.StandardInput.Flush();
output.AppendText(result + Environment.NewLine + sb);
sb.Clear();
}

else if ((!sb.ToString().StartsWith("[AES]") ^ sb.ToString().StartsWith("[ProtectedDataForCurrentUser]"))
&& sb.ToString().EndsWith("password:"))
{
var Password = new Password(ASF, sb.ToString());
Password.ShowDialog();
}

}
}

private void Check()
{
if (sb.ToString().Contains("Update process finished!"))
{
_asf.btnStop.PerformClick();
Task.Delay(1500).ContinueWith(t => _asf.btnStart.PerformClick());
_asf.btnStop.Invoke(new MethodInvoker(delegate { _asf.btnStop.PerformClick(); }));
Task.Delay(1500).ContinueWith(t => _asf.btnStart.Invoke(new MethodInvoker(delegate { _asf.btnStart.PerformClick(); })));
}

if (key != "")
Expand Down Expand Up @@ -154,20 +130,25 @@ private void Check()
}
}

if (!sb.ToString().Contains("Init() Success!") || loaded) return;
if (sb.ToString().Contains("Disconnected from Steam!"))
{
_asf.GetBotList();
}

if (!sb.ToString().Contains("Init() Success!")) return;
_asf.GetBotList();
loaded = true;
}

public void Start()
{
ASF.Start();
outputThread = new Thread(PrintOutput);
outputThread.Start();
new Thread(PrintOutput).Start();
}

public void Stop()
{
closeOutput = true;

if (ASF == null)
{
return;
Expand All @@ -182,7 +163,6 @@ public void Stop()
ASF.Kill();
}

closeOutput = true;
ASF = null;
}

Expand Down
13 changes: 10 additions & 3 deletions ASFui/ASFui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,18 @@ public void GetBotList()
cbBotList.Items.Add(m.Groups[1].Value);
}
}));
if (cbBotList.Items.Count <= 0) return;

cbBotList.Invoke(new MethodInvoker(delegate
{
cbBotList.SelectedIndex = 0;
EnableElements();
if (cbBotList.Items.Count <= 0)
{
btnStop.PerformClick();
}
else
{
cbBotList.SelectedIndex = 0;
EnableElements();
}
}));
}

Expand Down

0 comments on commit 2db2d42

Please sign in to comment.