Skip to content

Commit 4d0cd00

Browse files
author
Casper
committed
Removed HourBoostrJsonHelper and added a better program
* HourBoostrJsonHelper removed * Settings added to replace above * Fixed bugs and glitches in HourBoostr
1 parent 02ac7a1 commit 4d0cd00

77 files changed

Lines changed: 131998 additions & 7243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vs/HourBoostr/v14/.suo

-13.5 KB
Binary file not shown.

HourBoostr/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<configSections>
44
</configSections>
55
<startup>
6-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
6+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
77
</startup>
88
</configuration>

HourBoostr/Bot.cs

Lines changed: 105 additions & 85 deletions
Large diffs are not rendered by default.

HourBoostr/Config.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class Settings
2424
public List<AccountSettings> Accounts { get; set; } = new List<AccountSettings>();
2525
}
2626

27-
27+
2828
/// <summary>
29-
/// Class for account settings
29+
/// Holds account details
3030
/// </summary>
31-
public class AccountSettings
31+
public class Details
3232
{
3333
/// <summary>
3434
/// Username of steam account
@@ -49,6 +49,18 @@ public class AccountSettings
4949
/// Saving this means we don't have to enter code twice
5050
/// </summary>
5151
public string LoginKey { get; set; } = "";
52+
}
53+
54+
55+
/// <summary>
56+
/// Class for account settings
57+
/// </summary>
58+
public class AccountSettings
59+
{
60+
/// <summary>
61+
/// Holds all the account login information
62+
/// </summary>
63+
public Details Details { get; set; } = new Details();
5264

5365

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

5971

72+
/// <summary>
73+
/// If we should relog the account every 4 hours
74+
/// This will only be called if LoginKey is set
75+
/// </summary>
76+
public bool RelogEveryFourHours { get; set; }
77+
78+
6079
/// <summary>
6180
/// If we should authenticate to community
6281
/// </summary>

HourBoostr/HourBoostr.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>HourBoostr</RootNamespace>
1111
<AssemblyName>HourBoostr</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
@@ -43,9 +43,9 @@
4343
</Win32Resource>
4444
</PropertyGroup>
4545
<ItemGroup>
46-
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
47-
<SpecificVersion>False</SpecificVersion>
48-
<HintPath>.\Newtonsoft.Json.dll</HintPath>
46+
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
48+
<Private>True</Private>
4949
</Reference>
5050
<Reference Include="protobuf-net">
5151
<HintPath>.\protobuf-net.dll</HintPath>
@@ -90,6 +90,7 @@
9090
<ItemGroup>
9191
<Content Include="AppIcon.ico" />
9292
<Content Include="icon.ico" />
93+
<None Include="packages.config" />
9394
<None Include="Resources\icon.ico" />
9495
</ItemGroup>
9596
<ItemGroup>

HourBoostr/Program.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static bool ConsoleEventCallback(int eventType)
147147
/*eventType 2 being Exit event*/
148148
if (eventType == 2)
149149
{
150-
if (mSession?.mActiveBotList != null)
150+
if (mSession != null)
151151
{
152152
/*Disconnect all clients*/
153153
Console.WriteLine("\n\nDisconnecting...");
@@ -157,9 +157,8 @@ static bool ConsoleEventCallback(int eventType)
157157
Bot.mSteam.client.Disconnect();
158158
}
159159

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

@@ -204,6 +203,9 @@ static void Main(string[] args)
204203
if (settings.Accounts.Count > 0)
205204
{
206205
mSession = new Session(settings);
206+
while (mSession.mBwg.IsBusy)
207+
Thread.Sleep(250);
208+
207209
if (settings.HideToTrayAutomatically)
208210
{
209211
mTrayIcon.ShowBalloonTip(1000, "HourBoostr", "I'm down here!", ToolTipIcon.Info);
@@ -212,7 +214,7 @@ static void Main(string[] args)
212214
}
213215
else
214216
{
215-
Console.WriteLine("No accounts added! We got nothing to boost.");
217+
Console.WriteLine("No accounts were loaded from settings.");
216218
}
217219

218220
while (true)

HourBoostr/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.9.*")]
36-
[assembly: AssemblyFileVersion("1.9")]
36+
[assembly: AssemblyFileVersion("1.9.1")]

HourBoostr/Session.cs

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading;
5-
using Newtonsoft.Json;
64
using System.Reflection;
5+
using System.ComponentModel;
6+
using System.Windows.Forms;
77

88
namespace HourBoostr
99
{
@@ -16,10 +16,9 @@ class Session
1616

1717

1818
/// <summary>
19-
/// DateTime representing when all
20-
/// accounts were initialized
19+
/// Session background worker
2120
/// </summary>
22-
private DateTime mInitializedTime;
21+
public BackgroundWorker mBwg = new BackgroundWorker();
2322

2423

2524
/// <summary>
@@ -41,99 +40,93 @@ class Session
4140
public Session(Config.Settings settings)
4241
{
4342
mSettings = settings;
44-
StartBotAccounts();
45-
}
46-
47-
48-
/// <summary>
49-
/// Returns the DateTime of when the application was built
50-
/// </summary>
51-
/// <returns>DateTime</returns>
52-
private DateTime GetBuildDate()
53-
{
54-
var version = Assembly.GetEntryAssembly().GetName().Version;
55-
return new DateTime(2000, 1, 1).Add(new TimeSpan(
56-
TimeSpan.TicksPerDay * version.Build +
57-
TimeSpan.TicksPerSecond * 2 * version.Revision));
58-
}
59-
6043

61-
/// <summary>
62-
/// Gets the updated account settings from all active bots
63-
/// </summary>
64-
/// <returns>Config.Settings</returns>
65-
public Config.Settings GetUpdatedSettings()
66-
{
67-
var settings = mSettings;
68-
settings.Accounts = new List<Config.AccountSettings>();
69-
mActiveBotList.ForEach(o => settings.Accounts.Add(o.mAccountSettings));
70-
71-
return settings;
44+
mBwg.DoWork += MBwg_DoWork;
45+
mBwg.RunWorkerAsync();
7246
}
7347

7448

7549
/// <summary>
76-
/// Main function
77-
/// This is run on a seperate thread
78-
/// This will initialize the bots
50+
/// Backgroundworker to start all bots
7951
/// </summary>
80-
private void StartBotAccounts()
52+
private void MBwg_DoWork(object sender, DoWorkEventArgs e)
8153
{
8254
/*Go through account and log them into steam*/
8355
foreach (var account in mSettings.Accounts)
8456
{
85-
if (string.IsNullOrWhiteSpace(account.Username))
86-
continue;
87-
8857
var bot = new Bot(account);
8958
mActiveBotList.Add(bot);
9059

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

95-
if (mActiveBotList.Count == 0)
96-
{
97-
Console.WriteLine("No account were loaded.");
98-
Thread.Sleep(1500);
99-
Environment.Exit(1);
100-
}
101-
10266
/*Accounts statistics and some fucking baller ascii*/
10367
Console.Clear();
10468
Console.WriteLine($"\n _____ _ _ ");
10569
Console.WriteLine($" | | |___ _ _ ___| |_ ___ ___ ___| |_ ___ ");
10670
Console.WriteLine($" | | . | | | _| . | . | . |_ -| _| _|");
10771
Console.WriteLine($" |__|__|___|___|_| |___|___|___|___|_| |_| \n");
10872
Console.WriteLine($" Source: https://github.com/Ezzpify/");
109-
Console.WriteLine($" Build date: {GetBuildDate().ToString()}\n");
73+
Console.WriteLine($" Build date: {GetBuildDate().ToString()}");
74+
Console.WriteLine($" Version: {Application.ProductVersion}\n");
11075
Console.WriteLine($" ----------------------------------------");
11176
Console.WriteLine($"\n Loaded {mActiveBotList.Count} accounts\n\n Account list:");
112-
mActiveBotList.ForEach(o => Console.WriteLine(" {0} | {1} Games", o.mAccountSettings.Username, o.mSteam.games.Count));
77+
mActiveBotList.ForEach(o => Console.WriteLine(" {0} | {1} Games", o.mAccountSettings.Details.Username, o.mSteam.games.Count));
11378
Console.WriteLine($"\n\n Log:\n ----------------------------------------\n");
114-
mInitializedTime = DateTime.Now;
11579

11680
/*Start status thread*/
11781
mThreadStatus = new Thread(ThreadStatus);
11882
mThreadStatus.Start();
11983
}
12084

12185

86+
/// <summary>
87+
/// Returns the DateTime of when the application was built
88+
/// </summary>
89+
/// <returns>DateTime</returns>
90+
private DateTime GetBuildDate()
91+
{
92+
var version = Assembly.GetEntryAssembly().GetName().Version;
93+
return new DateTime(2000, 1, 1).Add(new TimeSpan(
94+
TimeSpan.TicksPerDay * version.Build +
95+
TimeSpan.TicksPerSecond * 2 * version.Revision));
96+
}
97+
98+
99+
/// <summary>
100+
/// Gets the updated account settings from all active bots
101+
/// </summary>
102+
/// <returns>Config.Settings</returns>
103+
public Config.Settings GetUpdatedSettings()
104+
{
105+
var settings = mSettings;
106+
settings.Accounts = new List<Config.AccountSettings>();
107+
mActiveBotList.ForEach(o => settings.Accounts.Add(o.mAccountSettings));
108+
109+
return settings;
110+
}
111+
112+
122113
/// <summary>
123114
/// Status for how long the bot has been running
124115
/// </summary>
125116
private void ThreadStatus()
126117
{
118+
var initializedTime = DateTime.Now;
119+
127120
while (true)
128121
{
129122
/*Get the current time then subtract the time when all bots were done initializing*/
130123
/*This will give us an idea of how long the bot has been running*/
131-
TimeSpan timeSpan = DateTime.Now - mInitializedTime;
124+
TimeSpan timeSpan = DateTime.Now - initializedTime;
132125
string timeSpentOnline = string.Format("{0} Hours {1} Minutes {2} Seconds",
133126
(timeSpan.Days * 24) + timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
134-
135-
Console.Title = string.Format("HourBoostr | Online for: {0}", timeSpentOnline);
136-
Thread.Sleep(1000);
127+
128+
Console.Title = $"{EndPoint.CONSOLE_TITLE} | Online for: {timeSpentOnline}";
129+
Thread.Sleep(800);
137130
}
138131
}
139132
}

HourBoostr/Settings.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using Newtonsoft.Json;
55
using System.Threading;
6+
using System.Linq;
67

78
namespace HourBoostr
89
{
@@ -27,15 +28,17 @@ public static Config.Settings GetSettings()
2728
};
2829

2930
File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
30-
Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}");
31-
Console.WriteLine("Please close the program and edit the settings.");
31+
Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}\nPlease close the program and edit the settings.");
3232
}
3333
else
3434
{
3535
var serializeSettings = new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Error };
3636
try
3737
{
38-
return JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
38+
var settings = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
39+
settings.Accounts = settings.Accounts.Where(o => !string.IsNullOrWhiteSpace(o.Details.Username)).Distinct().ToList();
40+
41+
return settings;
3942
}
4043
catch (Exception ex)
4144
{
@@ -58,33 +61,21 @@ public static Config.Settings GetSettings()
5861
/// <param name="oldSettings">Old settings</param>
5962
/// <param name="newSettings">New settings</param>
6063
/// <returns>Returns true if succeeded</returns>
61-
public static bool SaveSettings(Config.Settings oldSettings, Config.Settings newSettings)
64+
public static bool UpdateSettings(Config.Settings oldSettings, Config.Settings newSettings)
6265
{
6366
try
6467
{
65-
/*We'll compare the settings file when we launched the program to the current settings object*/
66-
/*This way we'll see if the user has made any changes to the settings file during runtime*/
67-
/*We'll compare the two classes as serialized strings, mostly because I cba to implement an Equals solution*/
68-
var currentFile = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
69-
if (JsonConvert.SerializeObject(currentFile) != JsonConvert.SerializeObject(oldSettings))
70-
{
71-
/*The settings file has been changed, so we'll make a copy of the one we have before overwriting it*/
72-
/*We'll do this so any changes that the user might have made don't get lost in the twisting nether*/
73-
string unixTimestamp = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
74-
File.Copy(EndPoint.SETTINGS_FILE_PATH, Path.GetFileNameWithoutExtension(EndPoint.SETTINGS_FILE_PATH) + $" backup ({unixTimestamp}).json");
75-
}
76-
7768
/*Now we'll go through all accounts and make sure we don't print out their password to the file
7869
if no password was originally set in the settings file*/
7970
foreach (var oldAcc in oldSettings.Accounts)
8071
{
81-
if (!string.IsNullOrWhiteSpace(oldAcc.Password))
72+
if (!string.IsNullOrWhiteSpace(oldAcc.Details.Password))
8273
continue;
8374

8475
foreach (var newAcc in newSettings.Accounts)
8576
{
86-
if (oldAcc.Username == newAcc.Username)
87-
newAcc.Password = string.Empty;
77+
if (oldAcc.Details.Username == newAcc.Details.Username)
78+
newAcc.Details.Password = string.Empty;
8879
}
8980
}
9081

HourBoostr/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
4+
</packages>

0 commit comments

Comments
 (0)