Skip to content

Commit

Permalink
Parameterize account creation delay. Enables support for servers that…
Browse files Browse the repository at this point in the history
… enforce the delay.
  • Loading branch information
ethanmoffat committed Sep 7, 2022
1 parent 5efa679 commit 414b2ea
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions EOLib.Config/ConfigDefaults.cs
Expand Up @@ -11,5 +11,7 @@ public static class ConfigDefaults

public const int NPCDropProtectionSeconds = 30;
public const int PlayerDropProtectionSeconds = 5;

public const int AccountCreateTimeout = 2000;
}
}
5 changes: 5 additions & 0 deletions EOLib.Config/ConfigFileLoadActions.cs
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using System;

namespace EOLib.Config
{
Expand Down Expand Up @@ -61,6 +62,10 @@ public void LoadConfigFile()
_configRepository.LogChatToFile = configFile.GetValue(ConfigStrings.Chat, ConfigStrings.LogChat, out tempBool) && tempBool;

_configRepository.MainCloneCompat = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.MainCloneCompat, out tempBool) && tempBool;
_configRepository.AccountCreateTimeout = TimeSpan.FromMilliseconds(
configFile.GetValue(ConfigStrings.Custom, ConfigStrings.AccountCreateTimeout, out tempInt)
? tempInt
: ConfigDefaults.AccountCreateTimeout);

string host;
_configRepository.Host = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Host, out host) ? host : ConfigDefaults.Host;
Expand Down
1 change: 1 addition & 0 deletions EOLib.Config/ConfigStrings.cs
Expand Up @@ -28,6 +28,7 @@ public static class ConfigStrings
public const string NPCDropProtectTime = "NPCDropProtectTime";
public const string PlayerDropProtectTime = "PlayerDropProtectTime";
public const string MainCloneCompat = nameof(MainCloneCompat);
public const string AccountCreateTimeout = nameof(AccountCreateTimeout);

public const string LANGUAGE = "LANGUAGE";
public const string Language = "Language";
Expand Down
7 changes: 7 additions & 0 deletions EOLib.Config/IConfigurationRepository.cs
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using System;

namespace EOLib.Config
{
Expand Down Expand Up @@ -31,6 +32,8 @@ public interface IConfigurationRepository

bool MainCloneCompat { get; set; }

TimeSpan AccountCreateTimeout { get; set; }

bool EnableLog { get; set; }
}

Expand Down Expand Up @@ -63,6 +66,8 @@ public interface IConfigurationProvider

bool MainCloneCompat { get; }

TimeSpan AccountCreateTimeout { get; }

bool EnableLog { get; }
}

Expand Down Expand Up @@ -96,6 +101,8 @@ public class ConfigurationRepository : IConfigurationRepository, IConfigurationP

public bool MainCloneCompat { get; set; }

public TimeSpan AccountCreateTimeout { get; set; }

public bool EnableLog { get; set; }
}
}
@@ -1,6 +1,7 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Services;
using EndlessClient.GameExecution;
using EOLib.Config;
using EOLib.Graphics;
using EOLib.Localization;
using XNAControls;
Expand All @@ -12,16 +13,19 @@ public class CreateAccountProgressDialogFactory : ICreateAccountProgressDialogFa
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IGameStateProvider _gameStateProvider;
private readonly IConfigurationProvider _configProvider;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IEODialogButtonService _eoDialogButtonService;

public CreateAccountProgressDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IGameStateProvider gameStateProvider,
IConfigurationProvider configProvider,
ILocalizedStringFinder localizedStringFinder,
IEODialogButtonService eoDialogButtonService)
{
_nativeGraphicsManager = nativeGraphicsManager;
_gameStateProvider = gameStateProvider;
_configProvider = configProvider;
_localizedStringFinder = localizedStringFinder;
_eoDialogButtonService = eoDialogButtonService;
}
Expand All @@ -33,6 +37,7 @@ public IXNADialog BuildCreateAccountProgressDialog()

return new ProgressDialog(_nativeGraphicsManager,
_gameStateProvider,
_configProvider,
_eoDialogButtonService,
message, caption);
}
Expand Down
9 changes: 7 additions & 2 deletions EndlessClient/Dialogs/ProgressDialog.cs
Expand Up @@ -3,6 +3,7 @@
using EndlessClient.Dialogs.Services;
using EndlessClient.GameExecution;
using EOLib;
using EOLib.Config;
using EOLib.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
Expand All @@ -12,6 +13,8 @@ namespace EndlessClient.Dialogs
{
public class ProgressDialog : BaseEODialog
{
private readonly IConfigurationProvider _configurationProvider;

private readonly IXNALabel _messageLabel, _captionLabel;
private readonly IXNAButton _cancelButton;

Expand All @@ -21,11 +24,14 @@ public class ProgressDialog : BaseEODialog

public ProgressDialog(INativeGraphicsManager nativeGraphicsManager,
IGameStateProvider gameStateProvider,
IConfigurationProvider configurationProvider,
IEODialogButtonService eoDialogButtonService,
string messageText,
string captionText)
: base(gameStateProvider)
{
_configurationProvider = configurationProvider;

BackgroundTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 18);

_messageLabel = new XNALabel(Constants.FontSize10)
Expand Down Expand Up @@ -79,8 +85,7 @@ protected override void OnUpdateControl(GameTime gt)
if (timeOpened == null)
timeOpened = gt.TotalGameTime;

const double SECONDS_FOR_CREATE = 2.0;
var pbPercent = (int)((gt.TotalGameTime.TotalSeconds - timeOpened.Value.TotalSeconds) / SECONDS_FOR_CREATE * 100);
var pbPercent = (int)((gt.TotalGameTime.TotalSeconds - timeOpened.Value.TotalSeconds) / _configurationProvider.AccountCreateTimeout.TotalSeconds * 100);
_pbWidth = (int)Math.Round(pbPercent / 100.0f * _pbBackgroundTexture.Width);

if (pbPercent >= 100)
Expand Down
16 changes: 16 additions & 0 deletions EndlessClient/GameExecution/GameRunnerBase.cs
Expand Up @@ -5,6 +5,7 @@
using EOLib.Config;
using EOLib.Graphics;
using EOLib.Localization;
using System;

#if !LINUX
using System.Windows.Forms;
Expand Down Expand Up @@ -95,6 +96,21 @@ public virtual bool SetupDependencies()

i++;
}
else if (string.Equals(arg, "--account_delay_ms") && i < _args.Length - 1)
{
var accountCreateTimeStr = _args[i + 1];
if (!int.TryParse(accountCreateTimeStr, out var accountCreateTime) || accountCreateTime < 2000)
{
Debug.WriteLine($"Account create timeout must be greater than or equal to 2000ms.");
}
else
{
_registry.Resolve<IConfigurationRepository>()
.AccountCreateTimeout = TimeSpan.FromMilliseconds(accountCreateTime);
}

i++;
}
else
{
Debug.WriteLine($"Unrecognized argument: {arg}. Will be ignored.");
Expand Down

0 comments on commit 414b2ea

Please sign in to comment.