public static async Task <Tuple <bool, int> > CreateGameWithRetry( int gameCount, Client client, BotConfiguration botConfiguration, AccountCharacter account) { var newGameCount = gameCount; var result = await GeneralHelpers.TryWithTimeout(async (retryCount) => { bool createGame = false; try { createGame = client.CreateGame(botConfiguration.Difficulty, $"{botConfiguration.GameNamePrefix}{newGameCount}", botConfiguration.GamePassword, botConfiguration.GameDescriptions[0]); } catch { } if (!createGame) { newGameCount++; var retryDuration = Math.Pow(1 + retryCount, 1.2) * TimeSpan.FromSeconds(3); Log.Information($"Creating game failed for {client.LoggedInUserName()} retrying in {retryDuration.TotalSeconds} seconds"); await RealmConnectHelpers.ConnectToRealmWithRetry(client, botConfiguration, account, 10); await Task.Delay(retryDuration); } return(createGame); }, TimeSpan.FromSeconds(15)); return(Tuple.Create(result, newGameCount)); }
public static async Task <bool> JoinGameWithRetry(int gameCount, Client client, BotConfiguration botConfiguration, AccountCharacter cowAccount) { return(await GeneralHelpers.TryWithTimeout(async (retryCount) => { bool joinGame = false; try { joinGame = client.JoinGame($"{botConfiguration.GameNamePrefix}{gameCount}", botConfiguration.GamePassword); } catch { } if (!joinGame) { var retryDuration = Math.Pow(1 + retryCount, 1.2) * TimeSpan.FromSeconds(3); Log.Information($"Joining game failed for {client.LoggedInUserName()} retrying in {retryDuration.TotalSeconds} seconds"); await RealmConnectHelpers.ConnectToRealmWithRetry(client, botConfiguration, cowAccount, 10); await Task.Delay(retryDuration); } return joinGame; }, TimeSpan.FromSeconds(20))); }