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

Commit

Permalink
Friendly API display. v0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
alvr committed Aug 2, 2016
1 parent 923548b commit c069adc
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 33 deletions.
81 changes: 81 additions & 0 deletions ASFui/API.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ASFui
{
public class Api
{
private readonly Bot.Root _data;
public Api(string result)
{
_data = JsonConvert.DeserializeObject<Bot.Root>(result);
}

private IEnumerable<string> GetBots()
{
return _data.Bot.Keys;
}

private static string GetAppName(uint id)
{
var url = "http://store.steampowered.com/api/appdetails?appids=" + id;
var content = new WebClient().DownloadString(url);
var json = JObject.Parse(content);
return json[id.ToString()]["data"]["name"].ToString();
}

public string AllApi()
{
var result = new StringBuilder();

foreach (var bot in GetBots())
{
result.Append(@"◈ Bot: " + bot + Environment.NewLine);
result.Append(@" ⟐ Active: " + _data.Bot[bot].KeepRunning + Environment.NewLine);

var games = _data.Bot[bot].CardsFarmer.GamesToFarm;
if (games.Keys.Count > 0)
{
result.Append(@" ⟐ Games to Farm:" + Environment.NewLine);

foreach (var game in games)
{
var timePlayed = TimeSpan.FromHours(game.Value);
result.Append(@" ◇ " + GetAppName(game.Key) + @"; Time Farmed: "
+ string.Format("{0:00}:{1:00}", timePlayed.Hours, timePlayed.Minutes) + Environment.NewLine);
}
}
else
{
result.Append(@" ⟐ Games to Farm: None" + Environment.NewLine);
}


var farming = _data.Bot[bot].CardsFarmer.CurrentGamesFarming;
if (farming.Count > 0)
{
result.Append(@" ⟐ Current Farming:" + Environment.NewLine);

foreach (var game in farming)
{
result.Append(@" ◇ " + GetAppName(game) + Environment.NewLine);
}
}
else
{
result.Append(@" ⟐ Current Farming: Nothing" + Environment.NewLine);
}

result.Append(@" ⟐ Manual: " + _data.Bot[bot].CardsFarmer.ManualMode + Environment.NewLine);

result.Append(Environment.NewLine);
}

return result.ToString();
}
}
}
17 changes: 6 additions & 11 deletions ASFui/ASFui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ private void BtnStart_Click(object sender, EventArgs e)
cbBotList.Enabled = true;
rtbOutput.Enabled = true;
btnReloadBots.Enabled = true;
btnReloadBots.Focus();
_asfRunning = true;
btnASFuiSettings.Enabled = false;
Task.Delay(1000).ContinueWith(b => GetBotList());
Task.Delay(2500).ContinueWith(b => GetBotList());
tsslCommandOutput.Text = @"Started ASF server.";
Logging.Info("Server started successfully.");
}
Expand Down Expand Up @@ -502,16 +501,12 @@ private void btnASFVersion_Click(object sender, EventArgs e)
private void btnAPI_Click(object sender, EventArgs e)
{
var result = Util.SendCommand("api");
if (_isLocal)
{
tsslCommandOutput.Text = @"!api: " + result;
}
else
Task.Run(() =>
{
rtbOutput.AppendText(@"!api: " + result + Environment.NewLine);
rtbOutput.SelectionStart = rtbOutput.Text.Length;
rtbOutput.ScrollToCaret();
}
var api = new Api(result);
MessageBox.Show(api.AllApi(), @"API result", MessageBoxButtons.OK);
});

}

#endregion
Expand Down
4 changes: 3 additions & 1 deletion ASFui/ASFui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.5\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -101,13 +101,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="API.cs" />
<Compile Include="ASFProcess.cs" />
<Compile Include="ASFui.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ASFui.Designer.cs">
<DependentUpon>ASFui.cs</DependentUpon>
</Compile>
<Compile Include="Bot.cs" />
<Compile Include="Client.cs" />
<Compile Include="Logging.cs" />
<Compile Include="Password.cs">
Expand Down
36 changes: 36 additions & 0 deletions ASFui/Bot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace ASFui
{
public class Bot
{
public class Root
{
[JsonProperty("Bots")]
public Dictionary<string, Bots> Bot { get; set; }
}

public class Bots
{
[JsonProperty("CardsFarmer")]
public CardsFarmer CardsFarmer { get; set; }

[JsonProperty("KeepRunning")]
public bool KeepRunning { get; set; }
}

public class CardsFarmer
{
[JsonProperty("GamesToFarm")]
public Dictionary<uint, float> GamesToFarm { get; set; }

[JsonProperty("CurrentGamesFarming")]
public HashSet<uint> CurrentGamesFarming { get; set; }

[JsonProperty("ManualMode")]
public bool ManualMode { get; set; }
}

}
}
23 changes: 17 additions & 6 deletions ASFui/NLog.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Layout"></xs:complexType>
<xs:complexType name="Filter" abstract="true"></xs:complexType>
<xs:complexType name="TimeSource" abstract="true"></xs:complexType>
<xs:simpleType name="SimpleLayoutAttribute">
Expand Down Expand Up @@ -1020,8 +1019,8 @@
<xs:element name="archiveFileName" minOccurs="0" maxOccurs="1" type="Layout" />
<xs:element name="archiveEvery" minOccurs="0" maxOccurs="1" type="NLog.Targets.FileArchivePeriod" />
<xs:element name="archiveAboveSize" minOccurs="0" maxOccurs="1" type="xs:long" />
<xs:element name="maxArchiveFiles" minOccurs="0" maxOccurs="1" type="xs:integer" />
<xs:element name="enableArchiveFileCompression" minOccurs="0" maxOccurs="1" type="xs:boolean" />
<xs:element name="maxArchiveFiles" minOccurs="0" maxOccurs="1" type="xs:integer" />
<xs:element name="forceManaged" minOccurs="0" maxOccurs="1" type="xs:boolean" />
<xs:element name="cleanupFileName" minOccurs="0" maxOccurs="1" type="xs:boolean" />
<xs:element name="fileName" minOccurs="0" maxOccurs="1" type="Layout" />
Expand Down Expand Up @@ -1093,14 +1092,14 @@
<xs:documentation>Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: </xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="maxArchiveFiles" type="xs:integer">
<xs:attribute name="enableArchiveFileCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Maximum number of archive files that should be kept.</xs:documentation>
<xs:documentation>Indicates whether to compress archive files into the zip archive format.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="enableArchiveFileCompression" type="xs:boolean">
<xs:attribute name="maxArchiveFiles" type="xs:integer">
<xs:annotation>
<xs:documentation>Indicates whether to compress archive files into the zip archive format.</xs:documentation>
<xs:documentation>Maximum number of archive files that should be kept.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="forceManaged" type="xs:boolean">
Expand Down Expand Up @@ -2238,6 +2237,18 @@
<xs:enumeration value="HttpGet" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="CompoundLayout">
<xs:complexContent>
<xs:extension base="Layout">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="layout" minOccurs="0" maxOccurs="unbounded" type="Layout" />
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Layout">
<xs:choice minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
<xs:complexType name="CsvLayout">
<xs:complexContent>
<xs:extension base="Layout">
Expand Down
7 changes: 0 additions & 7 deletions ASFui/Password.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ASFui
Expand Down
4 changes: 2 additions & 2 deletions ASFui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión
// mediante el carácter '*', como se muestra a continuación:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: AssemblyVersion("0.3.3.0")]
[assembly: AssemblyFileVersion("0.3.3.0")]
2 changes: 1 addition & 1 deletion ASFui/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ASFui/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class Util
{
public static bool CheckBinary()
{
return File.Exists(Settings.Default.ASFBinary);
return File.Exists(Settings.Default.ASFBinary) || !Settings.Default.IsLocal;
}

public static string SendCommand(string command)
Expand Down
6 changes: 3 additions & 3 deletions ASFui/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package id="Costura.Fody" version="1.3.3.0" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="1.29.4" targetFramework="net461" developmentDependency="true" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
<package id="NLog" version="4.3.5" targetFramework="net461" />
<package id="NLog.Config" version="4.3.5" targetFramework="net461" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net461" />
<package id="NLog" version="4.3.6" targetFramework="net461" />
<package id="NLog.Config" version="4.3.6.1" targetFramework="net461" />
<package id="NLog.Schema" version="4.3.6.1" targetFramework="net461" />
</packages>
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2.0
0.3.3.0

0 comments on commit c069adc

Please sign in to comment.