Skip to content

Commit

Permalink
Removed HourBoostrJsonHelper and added a better program
Browse files Browse the repository at this point in the history
* HourBoostrJsonHelper removed
* Settings added to replace above
* Fixed bugs and glitches in HourBoostr
  • Loading branch information
Casper committed Aug 2, 2016
1 parent 02ac7a1 commit 4d0cd00
Show file tree
Hide file tree
Showing 77 changed files with 131,998 additions and 7,243 deletions.
Binary file modified .vs/HourBoostr/v14/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion HourBoostr/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
190 changes: 105 additions & 85 deletions HourBoostr/Bot.cs

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions HourBoostr/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class Settings
public List<AccountSettings> Accounts { get; set; } = new List<AccountSettings>();
}


/// <summary>
/// Class for account settings
/// Holds account details
/// </summary>
public class AccountSettings
public class Details
{
/// <summary>
/// Username of steam account
Expand All @@ -49,6 +49,18 @@ public class AccountSettings
/// Saving this means we don't have to enter code twice
/// </summary>
public string LoginKey { get; set; } = "";
}


/// <summary>
/// Class for account settings
/// </summary>
public class AccountSettings
{
/// <summary>
/// Holds all the account login information
/// </summary>
public Details Details { get; set; } = new Details();


/// <summary>
Expand All @@ -57,6 +69,13 @@ public class AccountSettings
public bool ShowOnlineStatus { get; set; }


/// <summary>
/// If we should relog the account every 4 hours
/// This will only be called if LoginKey is set
/// </summary>
public bool RelogEveryFourHours { get; set; }


/// <summary>
/// If we should authenticate to community
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions HourBoostr/HourBoostr.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HourBoostr</RootNamespace>
<AssemblyName>HourBoostr</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -43,9 +43,9 @@
</Win32Resource>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="protobuf-net">
<HintPath>.\protobuf-net.dll</HintPath>
Expand Down Expand Up @@ -90,6 +90,7 @@
<ItemGroup>
<Content Include="AppIcon.ico" />
<Content Include="icon.ico" />
<None Include="packages.config" />
<None Include="Resources\icon.ico" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 7 additions & 5 deletions HourBoostr/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static bool ConsoleEventCallback(int eventType)
/*eventType 2 being Exit event*/
if (eventType == 2)
{
if (mSession?.mActiveBotList != null)
if (mSession != null)
{
/*Disconnect all clients*/
Console.WriteLine("\n\nDisconnecting...");
Expand All @@ -157,9 +157,8 @@ static bool ConsoleEventCallback(int eventType)
Bot.mSteam.client.Disconnect();
}

/*We'll fetch updated settings from all the
bots and overwrite the current settings file*/
if (Settings.SaveSettings(mSettings, mSession.mSettings))
/*Update settings*/
if (Settings.UpdateSettings(mSettings, mSession.mSettings))
Console.WriteLine("Updated user settings");
}

Expand Down Expand Up @@ -204,6 +203,9 @@ static void Main(string[] args)
if (settings.Accounts.Count > 0)
{
mSession = new Session(settings);
while (mSession.mBwg.IsBusy)
Thread.Sleep(250);

if (settings.HideToTrayAutomatically)
{
mTrayIcon.ShowBalloonTip(1000, "HourBoostr", "I'm down here!", ToolTipIcon.Info);
Expand All @@ -212,7 +214,7 @@ static void Main(string[] args)
}
else
{
Console.WriteLine("No accounts added! We got nothing to boost.");
Console.WriteLine("No accounts were loaded from settings.");
}

while (true)
Expand Down
2 changes: 1 addition & 1 deletion HourBoostr/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.*")]
[assembly: AssemblyFileVersion("1.9")]
[assembly: AssemblyFileVersion("1.9.1")]
99 changes: 46 additions & 53 deletions HourBoostr/Session.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
using System.Reflection;
using System.ComponentModel;
using System.Windows.Forms;

namespace HourBoostr
{
Expand All @@ -16,10 +16,9 @@ class Session


/// <summary>
/// DateTime representing when all
/// accounts were initialized
/// Session background worker
/// </summary>
private DateTime mInitializedTime;
public BackgroundWorker mBwg = new BackgroundWorker();


/// <summary>
Expand All @@ -41,99 +40,93 @@ class Session
public Session(Config.Settings settings)
{
mSettings = settings;
StartBotAccounts();
}


/// <summary>
/// Returns the DateTime of when the application was built
/// </summary>
/// <returns>DateTime</returns>
private DateTime GetBuildDate()
{
var version = Assembly.GetEntryAssembly().GetName().Version;
return new DateTime(2000, 1, 1).Add(new TimeSpan(
TimeSpan.TicksPerDay * version.Build +
TimeSpan.TicksPerSecond * 2 * version.Revision));
}


/// <summary>
/// Gets the updated account settings from all active bots
/// </summary>
/// <returns>Config.Settings</returns>
public Config.Settings GetUpdatedSettings()
{
var settings = mSettings;
settings.Accounts = new List<Config.AccountSettings>();
mActiveBotList.ForEach(o => settings.Accounts.Add(o.mAccountSettings));

return settings;
mBwg.DoWork += MBwg_DoWork;
mBwg.RunWorkerAsync();
}


/// <summary>
/// Main function
/// This is run on a seperate thread
/// This will initialize the bots
/// Backgroundworker to start all bots
/// </summary>
private void StartBotAccounts()
private void MBwg_DoWork(object sender, DoWorkEventArgs e)
{
/*Go through account and log them into steam*/
foreach (var account in mSettings.Accounts)
{
if (string.IsNullOrWhiteSpace(account.Username))
continue;

var bot = new Bot(account);
mActiveBotList.Add(bot);

/*We'll wait for the bot to log in before starting on the next bot
We won't wait for it to authenticate, should that be enabled*/
while (bot.mBotState == Bot.BotState.LoggedOut)
Thread.Sleep(100);
}

if (mActiveBotList.Count == 0)
{
Console.WriteLine("No account were loaded.");
Thread.Sleep(1500);
Environment.Exit(1);
}

/*Accounts statistics and some fucking baller ascii*/
Console.Clear();
Console.WriteLine($"\n _____ _ _ ");
Console.WriteLine($" | | |___ _ _ ___| |_ ___ ___ ___| |_ ___ ");
Console.WriteLine($" | | . | | | _| . | . | . |_ -| _| _|");
Console.WriteLine($" |__|__|___|___|_| |___|___|___|___|_| |_| \n");
Console.WriteLine($" Source: https://github.com/Ezzpify/");
Console.WriteLine($" Build date: {GetBuildDate().ToString()}\n");
Console.WriteLine($" Build date: {GetBuildDate().ToString()}");
Console.WriteLine($" Version: {Application.ProductVersion}\n");
Console.WriteLine($" ----------------------------------------");
Console.WriteLine($"\n Loaded {mActiveBotList.Count} accounts\n\n Account list:");
mActiveBotList.ForEach(o => Console.WriteLine(" {0} | {1} Games", o.mAccountSettings.Username, o.mSteam.games.Count));
mActiveBotList.ForEach(o => Console.WriteLine(" {0} | {1} Games", o.mAccountSettings.Details.Username, o.mSteam.games.Count));
Console.WriteLine($"\n\n Log:\n ----------------------------------------\n");
mInitializedTime = DateTime.Now;

/*Start status thread*/
mThreadStatus = new Thread(ThreadStatus);
mThreadStatus.Start();
}


/// <summary>
/// Returns the DateTime of when the application was built
/// </summary>
/// <returns>DateTime</returns>
private DateTime GetBuildDate()
{
var version = Assembly.GetEntryAssembly().GetName().Version;
return new DateTime(2000, 1, 1).Add(new TimeSpan(
TimeSpan.TicksPerDay * version.Build +
TimeSpan.TicksPerSecond * 2 * version.Revision));
}


/// <summary>
/// Gets the updated account settings from all active bots
/// </summary>
/// <returns>Config.Settings</returns>
public Config.Settings GetUpdatedSettings()
{
var settings = mSettings;
settings.Accounts = new List<Config.AccountSettings>();
mActiveBotList.ForEach(o => settings.Accounts.Add(o.mAccountSettings));

return settings;
}


/// <summary>
/// Status for how long the bot has been running
/// </summary>
private void ThreadStatus()
{
var initializedTime = DateTime.Now;

while (true)
{
/*Get the current time then subtract the time when all bots were done initializing*/
/*This will give us an idea of how long the bot has been running*/
TimeSpan timeSpan = DateTime.Now - mInitializedTime;
TimeSpan timeSpan = DateTime.Now - initializedTime;
string timeSpentOnline = string.Format("{0} Hours {1} Minutes {2} Seconds",
(timeSpan.Days * 24) + timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

Console.Title = string.Format("HourBoostr | Online for: {0}", timeSpentOnline);
Thread.Sleep(1000);
Console.Title = $"{EndPoint.CONSOLE_TITLE} | Online for: {timeSpentOnline}";
Thread.Sleep(800);
}
}
}
Expand Down
29 changes: 10 additions & 19 deletions HourBoostr/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using Newtonsoft.Json;
using System.Threading;
using System.Linq;

namespace HourBoostr
{
Expand All @@ -27,15 +28,17 @@ public static Config.Settings GetSettings()
};

File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}");
Console.WriteLine("Please close the program and edit the settings.");
Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}\nPlease close the program and edit the settings.");
}
else
{
var serializeSettings = new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Error };
try
{
return JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
var settings = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
settings.Accounts = settings.Accounts.Where(o => !string.IsNullOrWhiteSpace(o.Details.Username)).Distinct().ToList();

return settings;
}
catch (Exception ex)
{
Expand All @@ -58,33 +61,21 @@ public static Config.Settings GetSettings()
/// <param name="oldSettings">Old settings</param>
/// <param name="newSettings">New settings</param>
/// <returns>Returns true if succeeded</returns>
public static bool SaveSettings(Config.Settings oldSettings, Config.Settings newSettings)
public static bool UpdateSettings(Config.Settings oldSettings, Config.Settings newSettings)
{
try
{
/*We'll compare the settings file when we launched the program to the current settings object*/
/*This way we'll see if the user has made any changes to the settings file during runtime*/
/*We'll compare the two classes as serialized strings, mostly because I cba to implement an Equals solution*/
var currentFile = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
if (JsonConvert.SerializeObject(currentFile) != JsonConvert.SerializeObject(oldSettings))
{
/*The settings file has been changed, so we'll make a copy of the one we have before overwriting it*/
/*We'll do this so any changes that the user might have made don't get lost in the twisting nether*/
string unixTimestamp = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
File.Copy(EndPoint.SETTINGS_FILE_PATH, Path.GetFileNameWithoutExtension(EndPoint.SETTINGS_FILE_PATH) + $" backup ({unixTimestamp}).json");
}

/*Now we'll go through all accounts and make sure we don't print out their password to the file
if no password was originally set in the settings file*/
foreach (var oldAcc in oldSettings.Accounts)
{
if (!string.IsNullOrWhiteSpace(oldAcc.Password))
if (!string.IsNullOrWhiteSpace(oldAcc.Details.Password))
continue;

foreach (var newAcc in newSettings.Accounts)
{
if (oldAcc.Username == newAcc.Username)
newAcc.Password = string.Empty;
if (oldAcc.Details.Username == newAcc.Details.Username)
newAcc.Details.Password = string.Empty;
}
}

Expand Down
4 changes: 4 additions & 0 deletions HourBoostr/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
</packages>
Binary file not shown.

0 comments on commit 4d0cd00

Please sign in to comment.