1010using System . ComponentModel ;
1111using System . Net ;
1212using SteamKit2 . Internal ;
13+ using SteamKit2 . Discovery ;
1314using SteamKit2 ;
1415
1516namespace 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 ) )
0 commit comments