2018-03-27 00:54:20 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-12-31 19:48:58 -05:00
|
|
|
|
using System.Globalization;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using System.Linq;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
using System.Threading;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
using Data.Models;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models.Client;
|
2019-02-16 16:04:40 -05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
using SharedLibraryCore.Commands;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2022-04-21 13:39:09 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
using SharedLibraryCore.Dtos.Meta.Responses;
|
2022-06-15 20:37:34 -04:00
|
|
|
|
using SharedLibraryCore.Helpers;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using WebfrontCore.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ActionController : BaseController
|
|
|
|
|
{
|
2020-07-31 21:40:03 -04:00
|
|
|
|
private readonly ApplicationConfiguration _appConfig;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
private readonly IMetaServiceV2 _metaService;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
private readonly string _banCommandName;
|
|
|
|
|
private readonly string _tempbanCommandName;
|
|
|
|
|
private readonly string _unbanCommandName;
|
|
|
|
|
private readonly string _sayCommandName;
|
|
|
|
|
private readonly string _kickCommandName;
|
2022-06-11 12:34:00 -04:00
|
|
|
|
private readonly string _offlineMessageCommandName;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
private readonly string _flagCommandName;
|
|
|
|
|
private readonly string _unflagCommandName;
|
2020-08-06 09:48:14 -04:00
|
|
|
|
private readonly string _setLevelCommandName;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
private readonly string _setClientTagCommandName;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
private readonly string _addClientNoteCommandName;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
public ActionController(IManager manager, IEnumerable<IManagerCommand> registeredCommands,
|
2022-07-19 21:37:48 -04:00
|
|
|
|
ApplicationConfiguration appConfig, IMetaServiceV2 metaService) : base(manager)
|
2019-12-02 16:52:36 -05:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
_appConfig = appConfig;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
_metaService = metaService;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
|
|
|
|
|
foreach (var cmd in registeredCommands)
|
|
|
|
|
{
|
|
|
|
|
var type = cmd.GetType().Name;
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(BanCommand):
|
|
|
|
|
_banCommandName = cmd.Name;
|
|
|
|
|
break;
|
|
|
|
|
case nameof(TempBanCommand):
|
|
|
|
|
_tempbanCommandName = cmd.Name;
|
|
|
|
|
break;
|
|
|
|
|
case nameof(UnbanCommand):
|
|
|
|
|
_unbanCommandName = cmd.Name;
|
|
|
|
|
break;
|
2021-11-23 18:26:33 -05:00
|
|
|
|
// todo: this should be flag driven
|
|
|
|
|
case "SayCommand":
|
2020-08-04 18:26:16 -04:00
|
|
|
|
_sayCommandName = cmd.Name;
|
|
|
|
|
break;
|
|
|
|
|
case nameof(KickCommand):
|
|
|
|
|
_kickCommandName = cmd.Name;
|
|
|
|
|
break;
|
|
|
|
|
case nameof(FlagClientCommand):
|
|
|
|
|
_flagCommandName = cmd.Name;
|
|
|
|
|
break;
|
|
|
|
|
case nameof(UnflagClientCommand):
|
|
|
|
|
_unflagCommandName = cmd.Name;
|
|
|
|
|
break;
|
2020-08-06 09:48:14 -04:00
|
|
|
|
case nameof(SetLevelCommand):
|
|
|
|
|
_setLevelCommandName = cmd.Name;
|
|
|
|
|
break;
|
2022-06-11 12:34:00 -04:00
|
|
|
|
case "OfflineMessageCommand":
|
|
|
|
|
_offlineMessageCommandName = cmd.Name;
|
|
|
|
|
break;
|
2022-07-19 21:37:48 -04:00
|
|
|
|
case "SetClientTagCommand":
|
|
|
|
|
_setClientTagCommandName = cmd.Name;
|
|
|
|
|
break;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
case "AddClientNoteCommand":
|
|
|
|
|
_addClientNoteCommandName = cmd.Name;
|
|
|
|
|
break;
|
2020-08-04 18:26:16 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 00:54:20 -04:00
|
|
|
|
public IActionResult BanForm()
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_BAN_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_BAN_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "Reason",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
2018-09-02 17:59:27 -04:00
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "PresetReason",
|
|
|
|
|
Type = "select",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
|
|
|
|
|
Values = GetPresetPenaltyReasons()
|
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2020-12-31 19:48:58 -05:00
|
|
|
|
{
|
|
|
|
|
Name = "Duration",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_DURATION"],
|
|
|
|
|
Type = "select",
|
|
|
|
|
Values = _appConfig.BanDurations
|
|
|
|
|
.Select((item, index) => new
|
|
|
|
|
{
|
|
|
|
|
Id = (index + 1).ToString(),
|
|
|
|
|
Value = item.HumanizeForCurrentCulture()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.Append(new
|
|
|
|
|
{
|
|
|
|
|
Id = (_appConfig.BanDurations.Length + 1).ToString(),
|
|
|
|
|
Value = Localization["WEBFRONT_ACTION_SELECTION_PERMANENT"]
|
|
|
|
|
}).ToDictionary(duration => duration.Id, duration => duration.Value),
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-08-04 18:06:07 -04:00
|
|
|
|
Action = "BanAsync",
|
|
|
|
|
ShouldRefresh = true
|
2018-03-27 00:54:20 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
public async Task<IActionResult> BanAsync(int targetId, string reason, int duration, string presetReason = null)
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
var fallthroughReason = presetReason ?? reason;
|
|
|
|
|
string command;
|
|
|
|
|
// permanent
|
|
|
|
|
if (duration > _appConfig.BanDurations.Length)
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_banCommandName} @{targetId} {fallthroughReason}";
|
|
|
|
|
}
|
|
|
|
|
// temporary ban
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var durationSpan = _appConfig.BanDurations[duration - 1];
|
|
|
|
|
var durationValue = durationSpan.TotalHours.ToString(CultureInfo.InvariantCulture) +
|
|
|
|
|
Localization["GLOBAL_TIME_HOURS"][0];
|
|
|
|
|
command =
|
|
|
|
|
$"{_appConfig.CommandPrefix}{_tempbanCommandName} @{targetId} {durationValue} {fallthroughReason}";
|
2018-09-02 17:59:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 00:54:20 -04:00
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2018-09-02 17:59:27 -04:00
|
|
|
|
command
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 17:27:56 -04:00
|
|
|
|
public IActionResult UnbanForm(long? id)
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_UNBAN_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_UNBAN_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "Reason",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-08-04 18:06:07 -04:00
|
|
|
|
Action = "UnbanAsync",
|
|
|
|
|
ShouldRefresh = true
|
2018-03-27 00:54:20 -04:00
|
|
|
|
};
|
2022-06-05 17:27:56 -04:00
|
|
|
|
if (id is not null)
|
|
|
|
|
{
|
|
|
|
|
info.Inputs.Add(new()
|
|
|
|
|
{
|
|
|
|
|
Name = "targetId",
|
|
|
|
|
Value = id.ToString(),
|
|
|
|
|
Type = "hidden"
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> UnbanAsync(int targetId, string reason)
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_unbanCommandName} @{targetId} {reason}"
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
2018-04-04 15:38:34 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult LoginForm()
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var login = new ActionInfo
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LOGIN_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_LOGIN_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
2018-04-05 18:50:04 -04:00
|
|
|
|
Name = "clientId",
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_ID"],
|
|
|
|
|
Required = true
|
2018-04-04 15:38:34 -04:00
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
|
|
|
|
Name = "Password",
|
2018-05-05 18:52:04 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_PASSWORD"],
|
2018-04-04 15:38:34 -04:00
|
|
|
|
Type = "password",
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Required = true
|
2018-04-04 15:38:34 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Action = "Login"
|
2018-04-04 15:38:34 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", login);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> Login(int clientId, string password)
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
2022-06-11 12:34:00 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Login", "Account", new { clientId, password }));
|
2018-04-04 15:38:34 -04:00
|
|
|
|
}
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult EditForm()
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LABEL_EDIT"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_LABEL_EDIT"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "level",
|
|
|
|
|
Label = Localization["WEBFRONT_PROFILE_LEVEL"],
|
|
|
|
|
Type = "select",
|
2021-03-22 12:09:25 -04:00
|
|
|
|
Values = Enum.GetValues(typeof(EFClient.Permission)).OfType<EFClient.Permission>()
|
2018-09-02 17:59:27 -04:00
|
|
|
|
.Where(p => p <= Client.Level)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
.Where(p => p != EFClient.Permission.Banned)
|
|
|
|
|
.Where(p => p != EFClient.Permission.Flagged)
|
2020-12-31 19:48:58 -05:00
|
|
|
|
.ToDictionary(p => p.ToString(), p => p.ToLocalizedLevelName())
|
2018-09-02 17:59:27 -04:00
|
|
|
|
},
|
|
|
|
|
},
|
2019-08-04 18:06:07 -04:00
|
|
|
|
Action = "EditAsync",
|
|
|
|
|
ShouldRefresh = true
|
2018-09-02 17:59:27 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> EditAsync(int targetId, string level)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2020-08-06 09:48:14 -04:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_setLevelCommandName} @{targetId} {level}"
|
2018-09-02 17:59:27 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
2019-02-16 16:04:40 -05:00
|
|
|
|
|
2019-02-26 22:25:27 -05:00
|
|
|
|
public IActionResult GenerateLoginTokenForm()
|
2019-02-16 16:04:40 -05:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2019-02-16 16:04:40 -05:00
|
|
|
|
{
|
2020-08-17 22:21:11 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LABEL_GENERATE_TOKEN"],
|
2019-02-16 16:04:40 -05:00
|
|
|
|
Name = "GenerateLoginToken",
|
|
|
|
|
Action = "GenerateLoginTokenAsync",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
public string GenerateLoginTokenAsync()
|
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
var state = Manager.TokenAuthenticator.GenerateNextToken(new TokenIdentifier
|
|
|
|
|
{
|
2022-06-16 11:07:03 -04:00
|
|
|
|
ClientId = Client.ClientId
|
2022-06-15 20:37:34 -04:00
|
|
|
|
});
|
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"],
|
|
|
|
|
state.Token,
|
|
|
|
|
$"{state.RemainingTime} {Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}",
|
|
|
|
|
Client.ClientId);
|
2019-02-16 16:04:40 -05:00
|
|
|
|
}
|
2019-07-13 21:45:25 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult ChatForm(long id)
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2019-07-13 21:45:25 -04:00
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LABEL_SUBMIT_MESSAGE"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_LABEL_SUBMIT_MESSAGE"],
|
2019-07-13 21:45:25 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2019-07-13 21:45:25 -04:00
|
|
|
|
{
|
|
|
|
|
Name = "message",
|
|
|
|
|
Type = "text",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_MESSAGE"]
|
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2019-07-13 21:45:25 -04:00
|
|
|
|
{
|
|
|
|
|
Name = "id",
|
|
|
|
|
Value = id.ToString(),
|
|
|
|
|
Type = "hidden"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "ChatAsync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> ChatAsync(long id, string message)
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var server = Manager.GetServers().First(server => server.EndPoint == id);
|
2019-07-13 21:45:25 -04:00
|
|
|
|
|
2019-08-04 21:38:55 -04:00
|
|
|
|
server.ChatHistory.Add(new SharedLibraryCore.Dtos.ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
ClientId = Client.ClientId,
|
|
|
|
|
Message = message,
|
|
|
|
|
Name = Client.Name,
|
|
|
|
|
ServerGame = server.GameName,
|
|
|
|
|
Time = DateTime.Now
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2019-07-13 21:45:25 -04:00
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
2020-08-04 18:26:16 -04:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_sayCommandName} {message}"
|
2019-07-13 21:45:25 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
2019-07-16 16:27:19 -04:00
|
|
|
|
|
2022-04-25 17:12:25 -04:00
|
|
|
|
public async Task<IActionResult> RecentClientsForm(PaginationRequest request)
|
2019-07-16 16:27:19 -04:00
|
|
|
|
{
|
2022-04-25 17:12:25 -04:00
|
|
|
|
ViewBag.First = request.Offset == 0;
|
2022-06-11 12:34:00 -04:00
|
|
|
|
|
2022-04-25 17:13:18 -04:00
|
|
|
|
if (request.Count > 20)
|
2022-04-25 17:12:25 -04:00
|
|
|
|
{
|
2022-04-25 17:13:18 -04:00
|
|
|
|
request.Count = 20;
|
2022-04-25 17:12:25 -04:00
|
|
|
|
}
|
2022-06-11 12:34:00 -04:00
|
|
|
|
|
2022-04-25 17:12:25 -04:00
|
|
|
|
var clients = await Manager.GetClientService().GetRecentClients(request);
|
2022-04-28 12:42:23 -04:00
|
|
|
|
|
|
|
|
|
return request.Offset == 0
|
|
|
|
|
? View("~/Views/Shared/Components/Client/_RecentClientsContainer.cshtml", clients)
|
|
|
|
|
: View("~/Views/Shared/Components/Client/_RecentClients.cshtml", clients);
|
2019-07-16 16:27:19 -04:00
|
|
|
|
}
|
2022-06-11 12:34:00 -04:00
|
|
|
|
|
2022-04-21 13:39:09 -04:00
|
|
|
|
public IActionResult RecentReportsForm()
|
|
|
|
|
{
|
|
|
|
|
var serverInfo = Manager.GetServers().Select(server =>
|
|
|
|
|
new ServerInfo
|
|
|
|
|
{
|
|
|
|
|
Name = server.Hostname,
|
2022-06-11 12:34:00 -04:00
|
|
|
|
Reports = server.Reports.Where(report => (DateTime.UtcNow - report.ReportedOn).TotalHours <= 24)
|
|
|
|
|
.ToList()
|
2022-04-21 13:39:09 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View("Partials/_Reports", serverInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 18:06:07 -04:00
|
|
|
|
public IActionResult FlagForm()
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_FLAG_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_FLAG_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "reason",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2020-12-31 19:48:58 -05:00
|
|
|
|
{
|
|
|
|
|
Name = "PresetReason",
|
|
|
|
|
Type = "select",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
|
|
|
|
|
Values = GetPresetPenaltyReasons()
|
|
|
|
|
},
|
2019-08-04 18:06:07 -04:00
|
|
|
|
},
|
|
|
|
|
Action = "FlagAsync",
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
public async Task<IActionResult> FlagAsync(int targetId, string reason, string presetReason = null)
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
2020-12-31 19:48:58 -05:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_flagCommandName} @{targetId} {presetReason ?? reason}"
|
2019-08-04 18:06:07 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult UnflagForm()
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_UNFLAG_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_UNFLAG_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "reason",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
2019-08-04 18:06:07 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "UnflagAsync",
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> UnflagAsync(int targetId, string reason)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2019-08-04 18:06:07 -04:00
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
2020-08-04 18:26:16 -04:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_unflagCommandName} @{targetId} {reason}"
|
2019-08-04 18:06:07 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
2020-07-14 15:13:40 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult KickForm(int id)
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var info = new ActionInfo
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_KICK_NAME"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_KICK_NAME"],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
2020-12-31 19:48:58 -05:00
|
|
|
|
Name = "reason",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2020-12-31 19:48:58 -05:00
|
|
|
|
{
|
|
|
|
|
Name = "PresetReason",
|
|
|
|
|
Type = "select",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
|
|
|
|
|
Values = GetPresetPenaltyReasons()
|
2020-07-14 15:13:40 -04:00
|
|
|
|
},
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new()
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
|
|
|
|
Name = "targetId",
|
|
|
|
|
Type = "hidden",
|
|
|
|
|
Value = id.ToString()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "KickAsync",
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
public async Task<IActionResult> KickAsync(int targetId, string reason, string presetReason = null)
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var client = Manager.GetActiveClients().FirstOrDefault(client => client.ClientId == targetId);
|
2020-07-14 15:13:40 -04:00
|
|
|
|
|
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(Localization["WEBFRONT_ACTION_KICK_DISCONNECT"]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
2020-07-14 15:13:40 -04:00
|
|
|
|
{
|
|
|
|
|
serverId = client.CurrentServer.EndPoint,
|
2020-12-31 19:48:58 -05:00
|
|
|
|
command = $"{_appConfig.CommandPrefix}{_kickCommandName} {client.ClientNumber} {presetReason ?? reason}"
|
2020-07-14 15:13:40 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
2020-12-31 19:48:58 -05:00
|
|
|
|
|
2022-06-11 12:34:00 -04:00
|
|
|
|
public IActionResult DismissAlertForm(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo
|
|
|
|
|
{
|
2022-07-08 21:40:27 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_DISMISS_ALERT_FORM_SUBMIT"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_DISMISS_ALERT_SINGLE"],
|
2022-06-11 12:34:00 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Name = "alertId",
|
|
|
|
|
Type = "hidden",
|
|
|
|
|
Value = id.ToString()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = nameof(DismissAlert),
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult DismissAlert(Guid alertId)
|
|
|
|
|
{
|
|
|
|
|
AlertManager.MarkAlertAsRead(alertId);
|
|
|
|
|
return Json(new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo
|
|
|
|
|
{
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Response = Localization["WEBFRONT_ACTION_DISMISS_ALERT_SINGLE_RESPONSE"]
|
2022-06-11 12:34:00 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult DismissAllAlertsForm()
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo
|
|
|
|
|
{
|
2022-07-08 21:40:27 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_DISMISS_ALERT_FORM_SUBMIT"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_DISMISS_ALERT_MANY"],
|
2022-06-11 12:34:00 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Name = "targetId",
|
|
|
|
|
Type = "hidden",
|
|
|
|
|
Value = Client.ClientId.ToString()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = nameof(DismissAllAlerts),
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult DismissAllAlerts(int targetId)
|
|
|
|
|
{
|
|
|
|
|
AlertManager.MarkAllAlertsAsRead(targetId);
|
|
|
|
|
return Json(new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo
|
|
|
|
|
{
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Response = Localization["WEBFRONT_ACTION_DISMISS_ALERT_MANY_RESPONSE"]
|
2022-06-11 12:34:00 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult OfflineMessageForm()
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo
|
|
|
|
|
{
|
2022-07-08 21:40:27 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_OFFLINE_MESSAGE_FORM_SUBMIT"],
|
2022-07-05 13:02:43 -04:00
|
|
|
|
Name = Localization["WEBFRONT_ACTION_OFFLINE_MESSAGE_BUTTON_COMPOSE"],
|
2022-06-11 12:34:00 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Name = "message",
|
2022-07-08 21:40:27 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_OFFLINE_MESSAGE_FORM_CONTENT"],
|
2022-06-11 12:34:00 -04:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action = "OfflineMessage",
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> OfflineMessage(int targetId, string message)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
|
|
|
|
command =
|
|
|
|
|
$"{_appConfig.CommandPrefix}{_offlineMessageCommandName} @{targetId} {message.CapClientName(500)}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 21:37:48 -04:00
|
|
|
|
public async Task<IActionResult> SetClientTagForm(int id, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var tags = await _metaService.GetPersistentMetaValue<List<LookupValue<string>>>(EFMeta.ClientTagNameV2,
|
2022-07-20 12:39:46 -04:00
|
|
|
|
token) ?? new List<LookupValue<string>>();
|
2022-07-19 21:37:48 -04:00
|
|
|
|
var existingTag = await _metaService.GetPersistentMetaByLookup(EFMeta.ClientTagV2,
|
|
|
|
|
EFMeta.ClientTagNameV2, id, Manager.CancellationToken);
|
|
|
|
|
var info = new ActionInfo
|
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_SET_CLIENT_TAG_SUBMIT"],
|
2022-07-20 12:39:46 -04:00
|
|
|
|
Name = Localization["WEBFRONT_PROFILE_CONTEXT_MENU_TAG"],
|
2022-07-19 21:37:48 -04:00
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Name = "clientTag",
|
|
|
|
|
Type = "select",
|
2022-07-20 12:39:46 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_SET_CLIENT_TAG_FORM_TAG"],
|
2022-07-19 21:37:48 -04:00
|
|
|
|
Values = tags.ToDictionary(
|
|
|
|
|
item => item.Value == existingTag?.Value ? $"!selected!{item.Value}" : item.Value,
|
|
|
|
|
item => item.Value)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = nameof(SetClientTag),
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> SetClientTag(int targetId, string clientTag)
|
|
|
|
|
{
|
|
|
|
|
if (targetId <= 0 || string.IsNullOrWhiteSpace(clientTag))
|
|
|
|
|
{
|
|
|
|
|
return Json(new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo
|
|
|
|
|
{
|
|
|
|
|
Response = Localization["WEBFRONT_ACTION_SET_CLIENT_TAG_NONE"]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
|
|
|
|
command =
|
|
|
|
|
$"{_appConfig.CommandPrefix}{_setClientTagCommandName} @{targetId} {clientTag}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2022-07-20 11:32:26 -04:00
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> AddClientNoteForm(int id)
|
|
|
|
|
{
|
|
|
|
|
var existingNote = await _metaService.GetPersistentMetaValue<ClientNoteMetaResponse>("ClientNotes", id);
|
|
|
|
|
var info = new ActionInfo
|
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_CONFIGURATION_BUTTON_SAVE"],
|
|
|
|
|
Name = Localization["WEBFRONT_PROFILE_CONTEXT_MENU_NOTE"],
|
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
Name = "note",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_NOTE_FORM_NOTE"],
|
|
|
|
|
Value = existingNote?.Note,
|
|
|
|
|
Type = "textarea"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = nameof(AddClientNote),
|
|
|
|
|
ShouldRefresh = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> AddClientNote(int targetId, string note)
|
|
|
|
|
{
|
|
|
|
|
if (note?.Length > 350 || note?.Count(c => c == '\n') > 4)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status400BadRequest, new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo
|
|
|
|
|
{
|
|
|
|
|
Response = Localization["WEBFRONT_ACTION_NOTE_INVALID_LENGTH"]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
return await Task.FromResult(RedirectToAction("Execute", "Console", new
|
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
|
|
|
|
command =
|
|
|
|
|
$"{_appConfig.CommandPrefix}{_addClientNoteCommandName} @{targetId} {note}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2022-07-19 21:37:48 -04:00
|
|
|
|
|
2020-12-31 19:48:58 -05:00
|
|
|
|
private Dictionary<string, string> GetPresetPenaltyReasons() => _appConfig.PresetPenaltyReasons.Values
|
|
|
|
|
.Concat(_appConfig.GlobalRules)
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.Concat(_appConfig.Servers.SelectMany(server => server.Rules ?? Array.Empty<string>()))
|
2020-12-31 19:48:58 -05:00
|
|
|
|
.Distinct()
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.Select((value, _) => new
|
2020-12-31 19:48:58 -05:00
|
|
|
|
{
|
|
|
|
|
Value = value
|
|
|
|
|
})
|
|
|
|
|
// this is used for the default empty optional value
|
|
|
|
|
.Prepend(new
|
|
|
|
|
{
|
|
|
|
|
Value = ""
|
|
|
|
|
})
|
|
|
|
|
.ToDictionary(item => item.Value, item => item.Value);
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
2022-04-04 23:16:40 -04:00
|
|
|
|
}
|