fix issue with restarting via web

replace some hard coded string in javascript with localization
break things to fix things
This commit is contained in:
RaidMax 2019-05-17 09:02:09 -05:00
parent 5f588bb0f7
commit 0b0290a871
17 changed files with 134 additions and 129 deletions

View File

@ -104,7 +104,6 @@ namespace IW4MAdmin.Application.EventParsers
Type = GameEvent.EventType.Command, Type = GameEvent.EventType.Command,
Data = message, Data = message,
Origin = new EFClient() { NetworkId = originId }, Origin = new EFClient() { NetworkId = originId },
Target = Utilities.IW4MAdminClient(),
Message = message Message = message
}; };
} }
@ -114,7 +113,6 @@ namespace IW4MAdmin.Application.EventParsers
Type = GameEvent.EventType.Say, Type = GameEvent.EventType.Say,
Data = message, Data = message,
Origin = new EFClient() { NetworkId = originId }, Origin = new EFClient() { NetworkId = originId },
Target = Utilities.IW4MAdminClient(),
Message = message Message = message
}; };
} }
@ -166,8 +164,6 @@ namespace IW4MAdmin.Application.EventParsers
if (regexMatch.Success) if (regexMatch.Success)
{ {
bool isBot = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().Contains("bot");
return new GameEvent() return new GameEvent()
{ {
Type = GameEvent.EventType.PreConnect, Type = GameEvent.EventType.PreConnect,
@ -181,9 +177,7 @@ namespace IW4MAdmin.Application.EventParsers
NetworkId = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(), NetworkId = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(),
ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()), ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
State = EFClient.ClientState.Connecting, State = EFClient.ClientState.Connecting,
IsBot = isBot }
},
Target = Utilities.IW4MAdminClient()
}; };
} }
} }
@ -206,8 +200,7 @@ namespace IW4MAdmin.Application.EventParsers
NetworkId = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(), NetworkId = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(),
ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()), ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
State = EFClient.ClientState.Disconnecting State = EFClient.ClientState.Disconnecting
}, }
Target = Utilities.IW4MAdminClient()
}; };
} }
} }
@ -244,8 +237,7 @@ namespace IW4MAdmin.Application.EventParsers
{ {
Type = GameEvent.EventType.JoinTeam, Type = GameEvent.EventType.JoinTeam,
Data = logLine, Data = logLine,
Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong() }, Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong() }
Target = Utilities.IW4MAdminClient()
}; };
} }

View File

@ -57,13 +57,13 @@ namespace IW4MAdmin.Application.IO
try try
{ {
var gameEvent = Parser.GenerateGameEvent(eventLine); var gameEvent = Parser.GenerateGameEvent(eventLine);
// we don't want to add the even if ignoreBots is on and the event comes froma bot // we don't want to add the event if ignoreBots is on and the event comes from a bot
if (!ignoreBots.Value || (ignoreBots.Value && (gameEvent.Origin.NetworkId != -1 || gameEvent.Target.NetworkId != -1))) if (!ignoreBots.Value || (ignoreBots.Value && !((gameEvent.Origin?.IsBot ?? false) || (gameEvent.Target?.IsBot ?? false))))
{ {
gameEvent.Owner = server; gameEvent.Owner = server;
// we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin // we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin)
gameEvent.Origin = gameEvent.Origin.ClientId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId); gameEvent.Origin = gameEvent.Origin == null || gameEvent.Origin.NetworkId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId);
gameEvent.Target = gameEvent.Target.ClientId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId); gameEvent.Target = gameEvent.Target == null || gameEvent.Target.NetworkId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId);
events.Add(gameEvent); events.Add(gameEvent);
} }
@ -74,6 +74,7 @@ namespace IW4MAdmin.Application.IO
if (!ignoreBots.Value) if (!ignoreBots.Value)
{ {
server.Logger.WriteWarning("Could not find client in client list when parsing event line"); server.Logger.WriteWarning("Could not find client in client list when parsing event line");
server.Logger.WriteDebug(eventLine);
} }
} }

View File

@ -61,13 +61,13 @@ namespace IW4MAdmin.Application.IO
try try
{ {
var gameEvent = Parser.GenerateGameEvent(eventLine); var gameEvent = Parser.GenerateGameEvent(eventLine);
// we don't want to add the even if ignoreBots is on and the event comes froma bot // we don't want to add the event if ignoreBots is on and the event comes from a bot
if (!ignoreBots.Value || (ignoreBots.Value && (gameEvent.Origin.NetworkId != -1 || gameEvent.Target.NetworkId != -1))) if (!ignoreBots.Value || (ignoreBots.Value && !((gameEvent.Origin?.IsBot ?? false) || (gameEvent.Target?.IsBot ?? false))))
{ {
gameEvent.Owner = server; gameEvent.Owner = server;
// we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin // we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin)
gameEvent.Origin = gameEvent.Origin.ClientId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId); gameEvent.Origin = gameEvent.Origin == null || gameEvent.Origin.NetworkId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId);
gameEvent.Target = gameEvent.Target.ClientId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId); gameEvent.Target = gameEvent.Target == null || gameEvent.Target.NetworkId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId);
events.Add(gameEvent); events.Add(gameEvent);
} }
@ -81,6 +81,7 @@ namespace IW4MAdmin.Application.IO
if (!ignoreBots.Value) if (!ignoreBots.Value)
{ {
server.Logger.WriteWarning("Could not find client in client list when parsing event line"); server.Logger.WriteWarning("Could not find client in client list when parsing event line");
server.Logger.WriteDebug(eventLine);
} }
} }

View File

@ -38,8 +38,6 @@ namespace IW4MAdmin
{ {
Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved"); Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved");
try
{
EFClient client = await Manager.GetClientService().GetUnique(clientFromLog.NetworkId); EFClient client = await Manager.GetClientService().GetUnique(clientFromLog.NetworkId);
// first time client is connecting to server // first time client is connecting to server
@ -61,7 +59,6 @@ namespace IW4MAdmin
// Do the player specific stuff // Do the player specific stuff
client.ClientNumber = clientFromLog.ClientNumber; client.ClientNumber = clientFromLog.ClientNumber;
client.IsBot = clientFromLog.IsBot;
client.Score = clientFromLog.Score; client.Score = clientFromLog.Score;
client.Ping = clientFromLog.Ping; client.Ping = clientFromLog.Ping;
client.CurrentServer = this; client.CurrentServer = this;
@ -82,13 +79,6 @@ namespace IW4MAdmin
client.State = ClientState.Connected; client.State = ClientState.Connected;
} }
catch (Exception ex)
{
Logger.WriteError($"{loc["SERVER_ERROR_ADDPLAYER"]} {clientFromLog}");
Logger.WriteError(ex.GetExceptionInfo());
}
}
override public async Task OnClientDisconnected(EFClient client) override public async Task OnClientDisconnected(EFClient client)
{ {
#if DEBUG == true #if DEBUG == true
@ -229,7 +219,19 @@ namespace IW4MAdmin
#endif #endif
// we can go ahead and put them in so that they don't get re added // we can go ahead and put them in so that they don't get re added
Clients[E.Origin.ClientNumber] = E.Origin; Clients[E.Origin.ClientNumber] = E.Origin;
try
{
await OnClientConnected(E.Origin); await OnClientConnected(E.Origin);
}
catch (Exception ex)
{
Logger.WriteError($"{loc["SERVER_ERROR_ADDPLAYER"]} {E.Origin}");
Logger.WriteDebug(ex.GetExceptionInfo());
Clients[E.Origin.ClientNumber] = null;
return false;
}
ChatHistory.Add(new ChatInfo() ChatHistory.Add(new ChatInfo()
{ {

View File

@ -2,6 +2,7 @@
using SharedLibraryCore; using SharedLibraryCore;
using System; using System;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace IW4MAdmin.Application namespace IW4MAdmin.Application
@ -112,14 +113,19 @@ namespace IW4MAdmin.Application
WebfrontCore.Program.Init(ServerManager, ServerManager.CancellationToken) : WebfrontCore.Program.Init(ServerManager, ServerManager.CancellationToken) :
Task.CompletedTask; Task.CompletedTask;
// we want to run this one on a manual thread instead of letting the thread pool handle it,
// because we can't exit early from waiting on console input, and it prevents us from restarting
var inputThread = new Thread(async () => await ReadConsoleInput());
inputThread.Start();
var tasks = new[] var tasks = new[]
{ {
ServerManager.Start(), ServerManager.Start(),
webfrontTask, webfrontTask,
ReadConsoleInput(),
}; };
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

@ -155,7 +155,6 @@ namespace IW4MAdmin.Application.RconParsers
IPAddress = ip, IPAddress = ip,
Ping = ping, Ping = ping,
Score = score, Score = score,
IsBot = ip == null,
State = EFClient.ClientState.Connecting State = EFClient.ClientState.Connecting
}; };

View File

@ -499,7 +499,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
AttackerId = attacker.ClientId, AttackerId = attacker.ClientId,
VictimId = victim.ClientId, VictimId = victim.ClientId,
ServerId = serverId, ServerId = serverId,
Map = ParseEnum<IW4Info.MapName>.Get(map, typeof(IW4Info.MapName)), //Map = ParseEnum<IW4Info.MapName>.Get(map, typeof(IW4Info.MapName)),
DeathOrigin = vDeathOrigin, DeathOrigin = vDeathOrigin,
KillOrigin = vKillOrigin, KillOrigin = vKillOrigin,
DeathType = ParseEnum<IW4Info.MeansOfDeath>.Get(type, typeof(IW4Info.MeansOfDeath)), DeathType = ParseEnum<IW4Info.MeansOfDeath>.Get(type, typeof(IW4Info.MeansOfDeath)),
@ -1230,24 +1230,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
} }
public static async Task<long> GetIdForServer(Server server) public static async Task<long> GetIdForServer(Server server)
{
// hack: my laziness
if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28965")
{
return 886229536;
}
else if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28960")
{
return 1645744423;
}
else if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28970")
{
return 1645809959;
}
else
{ {
long id = HashCode.Combine(server.IP, server.GetPort()); long id = HashCode.Combine(server.IP, server.GetPort());
id = id < 0 ? Math.Abs(id) : id; id = id < 0 ? Math.Abs(id) : id;
@ -1270,4 +1252,3 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
} }
} }
} }
}

View File

@ -471,7 +471,7 @@ namespace IW4MAdmin.Plugins.Stats
/// <returns></returns> /// <returns></returns>
private bool ShouldIgnoreEvent(EFClient origin, EFClient target) private bool ShouldIgnoreEvent(EFClient origin, EFClient target)
{ {
return ((origin.ClientId <= 1 && target.ClientId <= 1) || ((target.IsBot || origin.IsBot) && ServerManager.GetApplicationSettings().Configuration().IgnoreBots)); return (origin.ClientId <= 1 && target.ClientId <= 1);
} }
} }
} }

View File

@ -712,7 +712,7 @@ namespace SharedLibraryCore.Database.Models
[NotMapped] [NotMapped]
public int Score { get; set; } public int Score { get; set; }
[NotMapped] [NotMapped]
public bool IsBot { get; set; } public bool IsBot => NetworkId == -1;
[NotMapped] [NotMapped]
public ClientState State { get; set; } public ClientState State { get; set; }

View File

@ -105,6 +105,7 @@ namespace WebfrontCore.Controllers
ViewBag.SocialLink = SocialLink ?? ""; ViewBag.SocialLink = SocialLink ?? "";
ViewBag.SocialTitle = SocialTitle; ViewBag.SocialTitle = SocialTitle;
ViewBag.Pages = Pages; ViewBag.Pages = Pages;
ViewBag.Localization = Utilities.CurrentLocalization.LocalizationIndex;
base.OnActionExecuting(context); base.OnActionExecuting(context);
} }

View File

@ -52,6 +52,9 @@ namespace WebfrontCore.Controllers
Manager.GetEventHandler().AddEvent(remoteEvent); Manager.GetEventHandler().AddEvent(remoteEvent);
List<CommandResponseInfo> response; List<CommandResponseInfo> response;
try
{
// wait for the event to process // wait for the event to process
if (!(await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken)).Failed) if (!(await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken)).Failed)
{ {
@ -75,6 +78,19 @@ namespace WebfrontCore.Controllers
} }
}; };
} }
}
catch (System.OperationCanceledException)
{
response = new List<CommandResponseInfo>()
{
new CommandResponseInfo()
{
ClientId = client.ClientId,
Response = Utilities.CurrentLocalization.LocalizationIndex["COMMADS_RESTART_SUCCESS"]
}
};
}
return View("_Response", response); return View("_Response", response);
} }

View File

@ -156,6 +156,13 @@
<environment include="Production"> <environment include="Production">
<script type="text/javascript" src="~/js/global.min.js"></script> <script type="text/javascript" src="~/js/global.min.js"></script>
</environment> </environment>
<script>
let _localizationTmp = @Html.Raw(Json.Serialize(ViewBag.Localization));
const _localization = [];
$.each(_localizationTmp.set, function (key, value) {
_localization[key] = value;
});
</script>
@RenderSection("scripts", required: false) @RenderSection("scripts", required: false)
</body> </body>
</html> </html>

View File

@ -7,7 +7,7 @@
} }
if (command[0] !== '!') { if (command[0] !== '!') {
$('#console_command_response').text('All commands must start with !').addClass('text-danger'); $('#console_command_response').text(_localization['WEBFRONT_CONSOLE_COMMAND']).addClass('text-danger');
return false; return false;
} }
showLoader(); showLoader();
@ -20,7 +20,7 @@
.fail(function (jqxhr, textStatus, error) { .fail(function (jqxhr, textStatus, error) {
errorLoader(); errorLoader();
hideLoader(); hideLoader();
$('#console_command_response').text('Could not execute command: ' + error).addClass('text-danger'); $('#console_command_response').text(_localization['WEBFRONT_CONSOLE_ERROR'] + error).addClass('text-danger');
}); });
} }

View File

@ -29,10 +29,10 @@ if ($('#penalty_table').length === 1) {
$('#penalty_filter_selection').change(function() { $('#penalty_filter_selection').change(function() {
location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val(); location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val();
}); });
/* /*
https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll
*/ */
$('html').bind('mousewheel DOMMouseScroll', function (e) { $('html').bind('mousewheel DOMMouseScroll', function (e) {
var delta = (e.originalEvent.wheelDelta || -e.originalEvent.detail); var delta = (e.originalEvent.wheelDelta || -e.originalEvent.detail);
@ -44,7 +44,6 @@ if ($('#penalty_table').length === 1) {
/* /*
https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom
*/ */
var _throttleTimer = null; var _throttleTimer = null;
var _throttleDelay = 100; var _throttleDelay = 100;
var $window = $(window); var $window = $(window);

View File

@ -60,33 +60,33 @@
$.getJSON('https://extreme-ip-lookup.com/json/' + ip) $.getJSON('https://extreme-ip-lookup.com/json/' + ip)
.done(function (response) { .done(function (response) {
$('#mainModal .modal-title').text(ip); $('#mainModal .modal-title').text(ip);
$('#mainModal .modal-body').text(""); $('#mainModal .modal-body').text('');
if (response.ipName.length > 0) { if (response.ipName.length > 0) {
$('#mainModal .modal-body').append("Hostname &mdash; " + response.ipName + '<br/>'); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_HOSTNAME']} &mdash; ${response.ipName}<br/>`);
} }
if (response.isp.length > 0) { if (response.isp.length > 0) {
$('#mainModal .modal-body').append("ISP &mdash; " + response.isp + '<br/>'); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_ISP']} &mdash; ${response.isp}<br/>`);
} }
if (response.org.length > 0) { if (response.org.length > 0) {
$('#mainModal .modal-body').append("Organization &mdash; " + response.org + '<br/>'); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_ORG']} &mdash; ${response.org}<br/>`);
} }
if (response['businessName'].length > 0) { if (response['businessName'].length > 0) {
$('#mainModal .modal-body').append("Business &mdash; " + response.businessName + '<br/>'); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_BUSINESS']} &mdash; ${response.businessName}<br/>`);
} }
if (response['businessWebsite'].length > 0) { if (response['businessWebsite'].length > 0) {
$('#mainModal .modal-body').append("Website &mdash; " + response.businessWebsite + '<br/>'); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_WEBSITE']} &mdash; ${response.businessWebsite}<br/>`);
} }
if (response.city.length > 0 || response.region.length > 0 || response.country.length > 0) { if (response.city.length > 0 || response.region.length > 0 || response.country.length > 0) {
$('#mainModal .modal-body').append("Location &mdash; "); $('#mainModal .modal-body').append(`${_localization['WEBFRONT_PROFILE_LOOKUP_LOCATION']} &mdash; `);
} }
if (response.city.length > 0) { if (response.city.length > 0) {
$('#mainModal .modal-body').append(response.city); $('#mainModal .modal-body').append(response.city);
} }
if (response.region.length > 0) { if (response.region.length > 0) {
$('#mainModal .modal-body').append(', ' + response.region); $('#mainModal .modal-body').append((response.city.length > 0 ? ', ' : '') + response.region);
} }
if (response.country.length > 0) { if (response.country.length > 0) {
$('#mainModal .modal-body').append(', ' + response.country); $('#mainModal .modal-body').append((response.country.length > 0 ? ', ' : '') + response.country);
} }
$('#mainModal').modal(); $('#mainModal').modal();

View File

@ -84,7 +84,7 @@ function refreshClientActivity() {
$('#server_clientactivity_' + serverId).html(response); $('#server_clientactivity_' + serverId).html(response);
}) })
.fail(function (jqxhr, textStatus, error) { .fail(function (jqxhr, textStatus, error) {
$('#server_clientactivity_' + serverId).html(" Could not load client activity - " + error); $('#server_clientactivity_' + serverId).html('');
}); });
}); });
} }

View File

@ -31,7 +31,7 @@
} }
}, },
title: { title: {
text: "Performance History", text: _localization['WEBFRONT_STATS_PERFORMANCE_HISTORY'],
fontSize: 14 fontSize: 14
}, },
axisX: { axisX: {
@ -39,14 +39,14 @@
lineThickness: 0, lineThickness: 0,
tickThickness: 0, tickThickness: 0,
margin: 0, margin: 0,
valueFormatString: " ", valueFormatString: ' ',
}, },
axisY: { axisY: {
labelFontSize: 12, labelFontSize: 12,
interval: interval, interval: interval,
gridThickness: 0, gridThickness: 0,
lineThickness: 0.5, lineThickness: 0.5,
valueFormatString: "#,##0", valueFormatString: '#,##0',
minimum: min, minimum: min,
maximum: max maximum: max
}, },
@ -54,7 +54,7 @@
dockInsidePlotArea: true dockInsidePlotArea: true
}, },
data: [{ data: [{
type: "splineArea", type: 'splineArea',
color: 'rgba(0, 122, 204, 0.25)', color: 'rgba(0, 122, 204, 0.25)',
markerSize: 3.5, markerSize: 3.5,
dataPoints: fixedData dataPoints: fixedData