Skip to content

Commit

Permalink
Merge pull request #141 from ChronosWS/BletchChanges
Browse files Browse the repository at this point in the history
ASM 299 Changes
  • Loading branch information
Bletch1971 authored Aug 14, 2017
2 parents 6b849fa + 5fbf7b8 commit da4652f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ARK Server Manager/ARK Server Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PublisherName>Ark Server Manager</PublisherName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.299.%2a</ApplicationVersion>
<ApplicationVersion>1.0.300.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>false</BootstrapperEnabled>
Expand Down
30 changes: 19 additions & 11 deletions ARK Server Manager/Lib/ServerRCON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ public class ServerRCON : DependencyObject, IAsyncDisposable
{
public event EventHandler PlayersCollectionUpdated;

private const int ListPlayersPeriod = 5000;
private const int GetChatPeriod = 1000;
private const int MaxCommandRetries = 10;
private const int RetryDelay = 100;
private const int LIST_PLAYERS_INTERVAL = 5000;
private const int GET_CHAT_INTERVAL = 1000;
private const string NoResponseMatch = "Server received, But no response!!";
public const string NoResponseOutput = "NO_RESPONSE";

Expand Down Expand Up @@ -71,6 +69,7 @@ public void Dispose()
private RCONParameters rconParams;
private QueryMaster.Rcon console;
private bool updatingPlayerDetails = false;
private int maxCommandRetries = 3;

private Logger chatLogger;
private Logger allLogger;
Expand Down Expand Up @@ -136,7 +135,7 @@ private Task AutoPlayerList()
return this.commandProcessor.PostAction(() =>
{
ProcessInput(new ConsoleCommand() { rawCommand = "listplayers", suppressCommand = true, suppressOutput = true });
Task.Delay(ListPlayersPeriod).ContinueWith(t => commandProcessor.PostAction(AutoPlayerList)).DoNotWait();
Task.Delay(LIST_PLAYERS_INTERVAL).ContinueWith(t => commandProcessor.PostAction(AutoPlayerList)).DoNotWait();
});
}

Expand All @@ -145,14 +144,19 @@ private Task AutoGetChat()
return this.commandProcessor.PostAction(() =>
{
ProcessInput(new ConsoleCommand() { rawCommand = "getchat", suppressCommand = true, suppressOutput = true });
Task.Delay(GetChatPeriod).ContinueWith(t => commandProcessor.PostAction(AutoGetChat)).DoNotWait();
Task.Delay(GET_CHAT_INTERVAL).ContinueWith(t => commandProcessor.PostAction(AutoGetChat)).DoNotWait();
});
}

public async Task DisposeAsync()
{
await this.commandProcessor.DisposeAsync();
await this.outputProcessor.DisposeAsync();

foreach (var listener in this.commandListeners)
{
listener.Dispose();
}
}

public IDisposable RegisterCommandListener(Action<ConsoleCommand> callback)
Expand Down Expand Up @@ -373,9 +377,12 @@ public Task<bool> IssueCommand(string userCommand)

private string SendCommand(string command)
{
int retries = 0;
const int RETRY_DELAY = 100;

Exception lastException = null;
while (retries < MaxCommandRetries)
int retries = 0;

while (retries < maxCommandRetries)
{
if (this.console != null)
{
Expand All @@ -386,11 +393,11 @@ private string SendCommand(string command)
}
catch (Exception ex)
{
// Re will simply retry
// we will simply retry
lastException = ex;
}

Task.Delay(RetryDelay).Wait();
Task.Delay(RETRY_DELAY).Wait();
}

try
Expand All @@ -405,8 +412,9 @@ private string SendCommand(string command)
retries++;
}

this.maxCommandRetries = 10;
errorLogger.Error($"Failed to connect to RCON at {this.rconParams.RCONHostIP}:{this.rconParams.RCONPort} with {this.rconParams.AdminPassword}. {lastException.Message}");
throw new Exception($"Command failed to send after {MaxCommandRetries} attempts. Last exception: {lastException.Message}", lastException);
throw new Exception($"Command failed to send after {maxCommandRetries} attempts. Last exception: {lastException.Message}", lastException);
}

private async Task UpdatePlayerDetails()
Expand Down
6 changes: 3 additions & 3 deletions ARK Server Manager/Windows/RCONWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ public RCONWindow(RCONParameters parameters)
this.RenderConnectionStateChange(a);
});

if (this.RCONParameters != null && this.RCONParameters.Server != null && this.RCONParameters.Server.Runtime != null)
if (this.RCONParameters?.Server?.Runtime != null)
{
this.RCONParameters.Server.Runtime.StatusUpdate += Runtime_StatusUpdate;
}

if (this.RCONParameters == null || this.RCONParameters.Server == null)
if (this.RCONParameters?.Server == null)
{
this.PlayerCountSeparator.Visibility = Visibility.Collapsed;
this.MaxPlayerLabel.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ private void Runtime_StatusUpdate(object sender, EventArgs eventArgs)

protected override void OnClosed(EventArgs e)
{
if (this.RCONParameters != null && this.RCONParameters.Server != null && this.RCONParameters.Server.Runtime != null)
if (this.RCONParameters?.Server?.Runtime != null)
{
this.RCONParameters.Server.Runtime.StatusUpdate -= Runtime_StatusUpdate;
}
Expand Down

0 comments on commit da4652f

Please sign in to comment.