Skip to content

Commit 12598b6

Browse files
committed
Added cellid and server list
1 parent a0631e5 commit 12598b6

17 files changed

Lines changed: 622 additions & 90 deletions

.vs/HourBoostr/v14/.suo

47.5 KB
Binary file not shown.

HourBoostr/Bot.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.ComponentModel;
1111
using System.Net;
1212
using SteamKit2.Internal;
13+
using SteamKit2.Discovery;
1314
using SteamKit2;
1415

1516
namespace HourBoostr
@@ -81,6 +82,12 @@ class ChatMessageData
8182
private int mDisconnectedCounter;
8283

8384

85+
/// <summary>
86+
/// How many diconnects that can occure before we force a pause
87+
/// </summary>
88+
private int mMaxDisconnectsBeforePause = 10;
89+
90+
8491
/// <summary>
8592
/// If we have connected once successfully this will be true
8693
/// Good to know if we disconnect
@@ -202,8 +209,15 @@ private void Connect()
202209
{
203210
mIsRunning = true;
204211
mLog.Write(Log.LogLevel.Info, $"Connecting to Steam ...");
205-
SteamDirectory.Initialize().Wait();
206-
mSteam.client.Connect();
212+
213+
try
214+
{
215+
mSteam.client.Connect();
216+
}
217+
catch (Exception ex)
218+
{
219+
mLog.Write(Log.LogLevel.Error, $"Error connecting to Steam: {ex}");
220+
}
207221
}
208222

209223

@@ -223,17 +237,17 @@ private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEvent
223237
}
224238
catch (Exception ex)
225239
{
226-
mLog.Write(Log.LogLevel.Warn, $"Exception occured for callbackManager: {ex}");
227-
errors++;
228-
229-
Thread.Sleep(5000);
230-
if (errors >= 3)
240+
mLog.Write(Log.LogLevel.Warn, $"Exception occured for callbackManager: {ex.Message}");
241+
if (errors++ >= 3)
231242
{
232-
/*This has historically only really occured when Steam is down
233-
so if too many errors here happen we'll pause for a while*/
243+
/*This has historically only really occured when Steam is down,
244+
but if too many errors happen here we'll pause*/
234245
mLog.Write(Log.LogLevel.Info, $"Pausing for 15 minutes due to too many errors occuring.");
235246
Thread.Sleep(TimeSpan.FromMinutes(15));
236247
}
248+
249+
if (!mSteam.client.IsConnected)
250+
Connect();
237251
}
238252
}
239253
}
@@ -297,7 +311,7 @@ private void OnDisconnected(SteamClient.DisconnectedCallback callback)
297311

298312
if (mIsRunning)
299313
{
300-
if (mDisconnectedCounter >= 5)
314+
if (mDisconnectedCounter >= mMaxDisconnectsBeforePause)
301315
{
302316
/*If we get too many disconnects it can be because the user has logged on
303317
their account and started playing, or steam is down. Either way we'll want
@@ -428,8 +442,8 @@ private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
428442
case EResult.NoConnection:
429443
case EResult.TryAnotherCM:
430444
case EResult.ServiceUnavailable:
431-
mLog.Write(Log.LogLevel.Warn, $"Service unavailable. We'll force a pause here.");
432-
mDisconnectedCounter = 4;
445+
mLog.Write(Log.LogLevel.Warn, $"Service unavailable. Waiting 1 minute.");
446+
Thread.Sleep(TimeSpan.FromMinutes(1));
433447
return;
434448
}
435449

@@ -445,6 +459,9 @@ private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
445459
mSteam.nounce = callback.WebAPIUserNonce;
446460
mBotState = BotState.LoggedIn;
447461

462+
if (callback.CellID != 0 && Program.mGlobalDB.CellID != callback.CellID)
463+
Program.mGlobalDB.CellID = callback.CellID;
464+
448465
mHasConnectedOnce = true;
449466
mDisconnectedCounter = 0;
450467
mPlayingBlocked = false;
@@ -519,9 +536,9 @@ private void OnFriendMsgCallback(SteamFriends.FriendMsgCallback callback)
519536
string friendUserName = mSteam.friends.GetFriendPersonaName(callback.Sender);
520537
mLogChat.Write(Log.LogLevel.Text, $"Msg from {friendUserName}: {callback.Message}");
521538

522-
/*Clear blocked users that are older than 20 minutes
539+
/*Clear blocked users that are older than 10 minutes
523540
This is to avoid responding every time a user is spamming us in the chat*/
524-
mSteamChatBlockList.RemoveAll(data => DateTime.Now.Subtract(data.DateReceived) > TimeSpan.FromMinutes(20));
541+
mSteamChatBlockList.RemoveAll(data => DateTime.Now.Subtract(data.DateReceived) > TimeSpan.FromMinutes(10));
525542

526543
/*Only send a response if one is set in the settings file*/
527544
if (!string.IsNullOrWhiteSpace(mAccountSettings.ChatResponse))

HourBoostr/ConcurrentEnumerator.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Threading;
5+
6+
namespace HourBoostr
7+
{
8+
/*
9+
* Credits for this part goes to JustArchi at:
10+
* https://github.com/JustArchi/ArchiSteamFarm
11+
*/
12+
13+
class ConcurrentEnumerator<T> : IEnumerator<T>
14+
{
15+
public T Current => Enumerator.Current;
16+
17+
private readonly IEnumerator<T> Enumerator;
18+
private readonly ReaderWriterLockSlim Lock;
19+
20+
object IEnumerator.Current => Current;
21+
22+
internal ConcurrentEnumerator(ICollection<T> collection, ReaderWriterLockSlim rwLock)
23+
{
24+
if ((collection == null) || (rwLock == null))
25+
{
26+
throw new ArgumentNullException(nameof(collection) + " || " + nameof(rwLock));
27+
}
28+
29+
rwLock.EnterReadLock();
30+
31+
Lock = rwLock;
32+
Enumerator = collection.GetEnumerator();
33+
}
34+
35+
public void Dispose() => Lock?.ExitReadLock();
36+
37+
public bool MoveNext() => Enumerator.MoveNext();
38+
public void Reset() => Enumerator.Reset();
39+
}
40+
}

HourBoostr/ConcurrentHashSet.cs

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Threading;
5+
6+
namespace HourBoostr
7+
{
8+
/*
9+
* Credits for this part goes to JustArchi at:
10+
* https://github.com/JustArchi/ArchiSteamFarm
11+
*/
12+
13+
class ConcurrentHashSet<T> : ICollection<T>, IDisposable
14+
{
15+
public int Count
16+
{
17+
get
18+
{
19+
Lock.EnterReadLock();
20+
21+
try
22+
{
23+
return HashSet.Count;
24+
}
25+
finally
26+
{
27+
Lock.ExitReadLock();
28+
}
29+
}
30+
}
31+
32+
public bool IsReadOnly => false;
33+
34+
private readonly HashSet<T> HashSet = new HashSet<T>();
35+
private readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
36+
37+
public void Clear()
38+
{
39+
Lock.EnterWriteLock();
40+
41+
try
42+
{
43+
HashSet.Clear();
44+
}
45+
finally
46+
{
47+
Lock.ExitWriteLock();
48+
}
49+
}
50+
51+
public bool Contains(T item)
52+
{
53+
Lock.EnterReadLock();
54+
55+
try
56+
{
57+
return HashSet.Contains(item);
58+
}
59+
finally
60+
{
61+
Lock.ExitReadLock();
62+
}
63+
}
64+
65+
public void CopyTo(T[] array, int arrayIndex)
66+
{
67+
Lock.EnterReadLock();
68+
69+
try
70+
{
71+
HashSet.CopyTo(array, arrayIndex);
72+
}
73+
finally
74+
{
75+
Lock.ExitReadLock();
76+
}
77+
}
78+
79+
public void Dispose() => Lock.Dispose();
80+
public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(HashSet, Lock);
81+
82+
public bool Remove(T item)
83+
{
84+
Lock.EnterWriteLock();
85+
86+
try
87+
{
88+
return HashSet.Remove(item);
89+
}
90+
finally
91+
{
92+
Lock.ExitWriteLock();
93+
}
94+
}
95+
96+
void ICollection<T>.Add(T item) => Add(item);
97+
98+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
99+
100+
internal void Add(T item)
101+
{
102+
Lock.EnterWriteLock();
103+
104+
try
105+
{
106+
HashSet.Add(item);
107+
}
108+
finally
109+
{
110+
Lock.ExitWriteLock();
111+
}
112+
}
113+
114+
internal void ClearAndTrim()
115+
{
116+
Lock.EnterWriteLock();
117+
118+
try
119+
{
120+
HashSet.Clear();
121+
HashSet.TrimExcess();
122+
}
123+
finally
124+
{
125+
Lock.ExitWriteLock();
126+
}
127+
}
128+
129+
internal bool ReplaceIfNeededWith(ICollection<T> items)
130+
{
131+
Lock.EnterUpgradeableReadLock();
132+
133+
try
134+
{
135+
if (HashSet.SetEquals(items))
136+
{
137+
return false;
138+
}
139+
140+
ReplaceWith(items);
141+
return true;
142+
}
143+
finally
144+
{
145+
Lock.ExitUpgradeableReadLock();
146+
}
147+
}
148+
149+
internal void ReplaceWith(IEnumerable<T> items)
150+
{
151+
Lock.EnterWriteLock();
152+
153+
try
154+
{
155+
HashSet.Clear();
156+
157+
foreach (T item in items)
158+
{
159+
HashSet.Add(item);
160+
}
161+
162+
HashSet.TrimExcess();
163+
}
164+
finally
165+
{
166+
Lock.ExitWriteLock();
167+
}
168+
}
169+
}
170+
}

HourBoostr/Config.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public class AccountSettings
9595
public bool JoinSteamGroup { get; set; } = true;
9696

9797

98+
/// <summary>
99+
/// If we should ignore running this account
100+
/// Useful if user doesn't want to boost a particular account right now but
101+
/// don't want to delete it from settings file because that's annoying as fuck
102+
/// </summary>
103+
public bool IgnoreAccount { get; set; } = false;
104+
105+
98106
/// <summary>
99107
/// What the bot should reply if someone sends it a message
100108
/// </summary>

HourBoostr/EndPoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace HourBoostr
66
class EndPoint
77
{
88
public static string SETTINGS_FILE_PATH = Path.Combine(Application.StartupPath, "Settings.json");
9+
public static string GLOBAL_SETTINGS_FILE_PATH = Path.Combine(Application.StartupPath, "GlobalDB.hb");
910
public static string SENTRY_FOLDER_PATH = Path.Combine(Application.StartupPath, "Sentryfiles");
1011
public static string LOG_FOLDER_PATH = Path.Combine(Application.StartupPath, "Logs");
1112
public static string CONSOLE_TITLE = $"HourBoostr v{Application.ProductVersion}";

0 commit comments

Comments
 (0)