Enhance Statistics

This will be used for public list of ASF STM bots in the future
This commit is contained in:
JustArchi 2016-12-04 01:07:37 +01:00
parent 59953faf1d
commit e480053f86
9 changed files with 111 additions and 15 deletions

View file

@ -136,6 +136,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharedInfo.cs" />
<Compile Include="Statistics.cs" />
<Compile Include="Trading.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="WCF.cs" />

View file

@ -665,6 +665,9 @@ namespace ArchiSteamFarm {
try {
await SteamApps.PICSGetProductInfo(0, null);
if (Program.GlobalConfig.Statistics) {
Statistics.OnHeartBeat(this).Forget();
}
} catch {
if (!IsConnectedAndLoggedOn || (HeartBeatFailures == byte.MaxValue)) {
return;
@ -1210,7 +1213,7 @@ namespace ArchiSteamFarm {
}
if (Program.GlobalConfig.Statistics) {
ArchiWebHandler.JoinGroup(SharedInfo.ASFGroupSteamID).Forget();
Statistics.OnLoggedOn(this).Forget();
}
Trading.CheckTrades().Forget();
@ -1320,7 +1323,10 @@ namespace ArchiSteamFarm {
}
if (callback.FriendID == SteamClient.SteamID) {
Events.OnStateUpdated(this, callback);
Events.OnPersonaState(this, callback);
if (Program.GlobalConfig.Statistics) {
Statistics.OnPersonaState(this, callback).Forget();
}
} else if ((callback.FriendID == LibraryLockedBySteamID) && (callback.GameID == 0)) {
LibraryLockedBySteamID = 0;
CheckOccupationStatus();

View file

@ -38,6 +38,6 @@ namespace ArchiSteamFarm {
Program.Shutdown();
}
internal static void OnStateUpdated(Bot bot, SteamFriends.PersonaStateCallback callback) { }
internal static void OnPersonaState(Bot bot, SteamFriends.PersonaStateCallback callback) { }
}
}

View file

@ -43,6 +43,7 @@ namespace ArchiSteamFarm {
internal const string LogFile = "log.txt";
internal const string ServiceDescription = "ASF is an application that allows you to farm steam cards using multiple steam accounts simultaneously.";
internal const string ServiceName = "ArchiSteamFarm";
internal const string StatisticsServer = "https://asf.justarchi.net";
internal const string VersionNumber = "2.1.7.0";
internal static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version;

View file

@ -0,0 +1,85 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
Contact: JustArchi@JustArchi.net
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SteamKit2;
namespace ArchiSteamFarm {
internal static class Statistics {
internal static async Task OnHeartBeat(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
const string request = SharedInfo.StatisticsServer + "/api/HeartBeat";
Dictionary<string, string> data = new Dictionary<string, string>(1) {
{ "SteamID", bot.SteamID.ToString() }
};
// We don't need retry logic here
await Program.WebBrowser.UrlPost(request, data).ConfigureAwait(false);
}
internal static async Task OnLoggedOn(Bot bot) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;
}
await bot.ArchiWebHandler.JoinGroup(SharedInfo.ASFGroupSteamID).ConfigureAwait(false);
const string request = SharedInfo.StatisticsServer + "/api/LoggedOn";
Dictionary<string, string> data = new Dictionary<string, string>(4) {
{ "SteamID", bot.SteamID.ToString() },
{ "HasMobileAuthenticator", bot.HasMobileAuthenticator ? "1" : "0" },
{ "SteamTradeMatcher", bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.SteamTradeMatcher) ? "1" : "0" },
{ "MatchEverything", bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchEverything) ? "1" : "0" }
};
// We don't need retry logic here
await Program.WebBrowser.UrlPost(request, data).ConfigureAwait(false);
}
internal static async Task OnPersonaState(Bot bot, SteamFriends.PersonaStateCallback callback) {
if ((bot == null) || (callback == null)) {
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(callback));
return;
}
string avatarHash = BitConverter.ToString(callback.AvatarHash).Replace("-", "").ToLowerInvariant();
const string request = SharedInfo.StatisticsServer + "/api/PersonaState";
Dictionary<string, string> data = new Dictionary<string, string>(2) {
{ "SteamID", bot.SteamID.ToString() },
{ "AvatarHash", avatarHash }
};
// We don't need retry logic here
await Program.WebBrowser.UrlPost(request, data).ConfigureAwait(false);
}
}
}

View file

@ -219,6 +219,17 @@ namespace ArchiSteamFarm {
return null;
}
internal async Task<bool> UrlPost(string request, IEnumerable<KeyValuePair<string, string>> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
ArchiLogger.LogNullError(nameof(request));
return false;
}
using (HttpResponseMessage response = await UrlPostToResponse(request, data, referer).ConfigureAwait(false)) {
return response != null;
}
}
internal async Task<bool> UrlPostRetry(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
ArchiLogger.LogNullError(nameof(request));
@ -428,17 +439,6 @@ namespace ArchiSteamFarm {
}
}
private async Task<bool> UrlPost(string request, IEnumerable<KeyValuePair<string, string>> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
ArchiLogger.LogNullError(nameof(request));
return false;
}
using (HttpResponseMessage response = await UrlPostToResponse(request, data, referer).ConfigureAwait(false)) {
return response != null;
}
}
private async Task<string> UrlPostToContent(string request, IEnumerable<KeyValuePair<string, string>> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
ArchiLogger.LogNullError(nameof(request));

View file

@ -31,7 +31,7 @@ namespace ArchiSteamFarm {
internal static class Events {
internal static void OnBotShutdown() { }
internal static void OnStateUpdated(Bot bot, SteamFriends.PersonaStateCallback callback) {
internal static void OnPersonaState(Bot bot, SteamFriends.PersonaStateCallback callback) {
if (bot == null) {
ASF.ArchiLogger.LogNullError(nameof(bot));
return;

View file

@ -145,6 +145,9 @@
<Compile Include="..\ArchiSteamFarm\SharedInfo.cs">
<Link>SharedInfo.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\Statistics.cs">
<Link>Statistics.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\Trading.cs">
<Link>Trading.cs</Link>
</Compile>

BIN
resources/Statistics.mwb Normal file

Binary file not shown.