Merge pull request #96 from RaidMax/enhancement/issue-91-check-sv-running

implement feedback from issue #91 when sv_running is off
This commit is contained in:
RaidMax 2020-01-13 16:54:38 -06:00 committed by GitHub
commit 9be7bafc53
7 changed files with 30 additions and 8 deletions

View File

@ -835,6 +835,7 @@ namespace IW4MAdmin
Logger.WriteDebug(e.GetExceptionInfo()); Logger.WriteDebug(e.GetExceptionInfo());
} }
Logger.WriteError(e.Message);
return false; return false;
} }
@ -876,6 +877,13 @@ namespace IW4MAdmin
Version = RconParser.Version; Version = RconParser.Version;
} }
var svRunning = await this.GetDvarAsync<int>("sv_running");
if (svRunning.Value == 0)
{
throw new ServerException(loc["SERVER_ERROR_NOT_RUNNING"]);
}
var infoResponse = RconParser.Configuration.CommandPrefixes.RConGetInfo != null ? await this.GetInfoAsync() : null; var infoResponse = RconParser.Configuration.CommandPrefixes.RConGetInfo != null ? await this.GetInfoAsync() : null;
// this is normally slow, but I'm only doing it because different games have different prefixes // this is normally slow, but I'm only doing it because different games have different prefixes
var hostname = infoResponse == null ? var hostname = infoResponse == null ?

View File

@ -130,7 +130,6 @@ namespace IW4MAdmin.Application
}; };
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
inputThread.Abort();
ServerManager.Logger.WriteVerbose(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_SHUTDOWN_SUCCESS"]); ServerManager.Logger.WriteVerbose(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_SHUTDOWN_SUCCESS"]);
} }

View File

@ -36,6 +36,7 @@ namespace IW4MAdmin.Application.RconParsers
RConGetInfo = "ÿÿÿÿgetinfo", RConGetInfo = "ÿÿÿÿgetinfo",
RConResponse = "ÿÿÿÿprint", RConResponse = "ÿÿÿÿprint",
}, },
ServerNotRunningResponse = "Server is not running."
}; };
Configuration.Status.Pattern = @"^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){8,32}|(?:[a-z]|[0-9]){8,32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback|unknown) +(-*[0-9]+) +([0-9]+) *$"; Configuration.Status.Pattern = @"^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){8,32}|(?:[a-z]|[0-9]){8,32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback|unknown) +(-*[0-9]+) +([0-9]+) *$";
@ -141,7 +142,7 @@ namespace IW4MAdmin.Application.RconParsers
if (Status.Length < 4) if (Status.Length < 4)
{ {
throw new ServerException("Unexpected status response received"); throw new ServerException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNEXPECTED_STATUS"]);
} }
int validMatches = 0; int validMatches = 0;
@ -208,7 +209,7 @@ namespace IW4MAdmin.Application.RconParsers
// this happens if status is requested while map is rotating // this happens if status is requested while map is rotating
if (Status.Length > 5 && validMatches == 0) if (Status.Length > 5 && validMatches == 0)
{ {
throw new ServerException("Server is rotating map"); throw new ServerException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_ROTATING_MAP"]);
} }
return StatusPlayers; return StatusPlayers;

View File

@ -1,5 +1,4 @@
using SharedLibraryCore; using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.RCon; using SharedLibraryCore.RCon;
namespace IW4MAdmin.Application.RconParsers namespace IW4MAdmin.Application.RconParsers
@ -14,6 +13,7 @@ namespace IW4MAdmin.Application.RconParsers
public ParserRegex Status { get; set; } = new ParserRegex(); public ParserRegex Status { get; set; } = new ParserRegex();
public ParserRegex MapStatus { get; set; } = new ParserRegex(); public ParserRegex MapStatus { get; set; } = new ParserRegex();
public ParserRegex Dvar { get; set; } = new ParserRegex(); public ParserRegex Dvar { get; set; } = new ParserRegex();
public string ServerNotRunningResponse { get; set; }
public bool WaitForResponse { get; set; } = true; public bool WaitForResponse { get; set; } = true;
} }
} }

View File

@ -257,13 +257,16 @@ namespace SharedLibraryCore
{ {
processed = await Task.Run(() => _eventFinishedWaiter.WaitOne(timeSpan), token); processed = await Task.Run(() => _eventFinishedWaiter.WaitOne(timeSpan), token);
} }
catch { }
catch (TaskCanceledException)
{
processed = true;
}
if (!processed) if (!processed)
{ {
#if DEBUG #if DEBUG
//throw new Exception(); throw new Exception();
#endif #endif
Owner?.Logger.WriteError("Waiting for event to complete timed out"); Owner?.Logger.WriteError("Waiting for event to complete timed out");
Owner?.Logger.WriteDebug($"{Id}, {Type}, {Data}, {Extra}, {FailReason.ToString()}, {Message}, {Origin}, {Target}"); Owner?.Logger.WriteDebug($"{Id}, {Type}, {Data}, {Extra}, {FailReason.ToString()}, {Message}, {Origin}, {Target}");

View File

@ -24,6 +24,11 @@ namespace SharedLibraryCore.Interfaces
/// </summary> /// </summary>
ParserRegex Dvar { get; set; } ParserRegex Dvar { get; set; }
/// <summary>
/// Specifies the expected response message from rcon when the server is not running
/// </summary>
string ServerNotRunningResponse { get; set; }
/// <summary> /// <summary>
/// indicates if the application should wait for response from server /// indicates if the application should wait for response from server
/// when executing a command /// when executing a command

View File

@ -184,16 +184,22 @@ namespace SharedLibraryCore.RCon
string responseString = defaultEncoding.GetString(response, 0, response.Length) + '\n'; string responseString = defaultEncoding.GetString(response, 0, response.Length) + '\n';
// note: not all games respond if the pasword is wrong or not set
if (responseString.Contains("Invalid password") || responseString.Contains("rconpassword")) if (responseString.Contains("Invalid password") || responseString.Contains("rconpassword"))
{ {
throw new NetworkException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_RCON_INVALID"]); throw new NetworkException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_RCON_INVALID"]);
} }
if (responseString.ToString().Contains("rcon_password")) if (responseString.Contains("rcon_password"))
{ {
throw new NetworkException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_RCON_NOTSET"]); throw new NetworkException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_RCON_NOTSET"]);
} }
if (responseString.Contains(Config.ServerNotRunningResponse))
{
throw new ServerException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_NOT_RUNNING"].FormatExt(Endpoint.ToString()));
}
string[] splitResponse = responseString.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries) string[] splitResponse = responseString.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Trim()) .Select(line => line.Trim())
.ToArray(); .ToArray();